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: