Using rustfmt as a library?

I'm trying to debug a proc-macro, and am wondering if there is a nice way to use rustfmt as a library? It's got very sparse documentation. I'm just looking for a way to format my proc_macro2::TokenStream such that I can effectively read it as rust code. Any other way to pretty print rust code would also work, if anyone has a suggestion.

In rust-analyzer, we just shell out to the rustfmt binary for similar purposes: https://github.com/rust-analyzer/rust-analyzer/blob/ada9e16537c22b490d13cdd54b9e1e4885856a4c/xtask/src/codegen.rs#L66