Crate rust_format
source · [−]Expand description
A Rust source code formatting crate with a unified interface for string, file, and
TokenStream input. It currently supports
rustfmt and
prettyplease.
use rust_format::{Formatter, RustFmt};
let source = r#"fn main() { println!("Hello World!"); }"#;
let actual = RustFmt::default().format_str(source).unwrap();
let expected = r#"fn main() {
println!("Hello World!");
}
"#;
assert_eq!(expected, actual);
Structs
The configuration for the formatters. Other than edition, these options should be considered proprietary to the formatter being used. They are not portable between formatters.
This formatter uses prettyplease for formatting source code
This formatter uses rustfmt
for formatting source code
Enums
The Rust edition the source code uses
This error is returned when errors are triggered during the formatting process
Traits
A unified interface to all formatters. It allows for formatting from string, file, or
TokenStream (feature token_stream
required)