pub trait Formatter {
// Required method
fn format_str(&self, source: impl AsRef<str>) -> Result<String, Error>;
// Provided methods
fn format_file(&self, path: impl AsRef<Path>) -> Result<(), Error> { ... }
fn format_tokens(&self, tokens: TokenStream) -> Result<String, Error> { ... }
}
Expand description
A unified interface to all formatters. It allows for formatting from string, file, or TokenStream
Required Methods§
Provided Methods§
Sourcefn format_file(&self, path: impl AsRef<Path>) -> Result<(), Error>
fn format_file(&self, path: impl AsRef<Path>) -> Result<(), Error>
Format the given file specified hte path and overwrite the file with the results. An error is returned if any issues occur during formatting
Sourcefn format_tokens(&self, tokens: TokenStream) -> Result<String, Error>
Available on crate feature token_stream
only.
fn format_tokens(&self, tokens: TokenStream) -> Result<String, Error>
token_stream
only.Format the given TokenStream and return the results in a String
.
An error is returned if any issues occur during formatting
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.