pub struct RustFmt { /* private fields */ }
Expand description

This formatter uses rustfmt for formatting source code

An example using a custom configuration:

use std::collections::HashMap;
use rust_format::{Config, Edition, Formatter, RustFmt};

let source = r#"use std::marker; use std::io; mod test; mod impls;"#;

let mut options = HashMap::with_capacity(2);
options.insert("reorder_imports", "false");
options.insert("reorder_modules", "false");

let config = Config::new(Edition::Rust2018, options);
let rustfmt = RustFmt::from_config(config);

let actual = rustfmt.format_str(source).unwrap();
let expected = r#"use std::marker;
use std::io;
mod test;
mod impls;
"#;

assert_eq!(expected, actual);

Implementations

Creates a new instance of the formatter from the given configuration

Trait Implementations

Returns the “default value” for a type. Read more

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

Format the given file specified hte path and overwrite the file with the results. An error is returned if any issues occur during formatting Read more

Format the given TokenStream and return the results in a String. An error is returned if any issues occur during formatting Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.