rust_format

Trait Formatter

Source
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§

Source

fn format_str(&self, source: impl AsRef<str>) -> Result<String, Error>

Format the given string and return the results in another String. An error is returned if any issues occur during formatting

Provided Methods§

Source

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

Source

fn format_tokens(&self, tokens: TokenStream) -> Result<String, Error>

Available on crate feature 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.

Implementors§