Struct rust_format::RustFmt
source · [−]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
Trait Implementations
sourceimpl Formatter for RustFmt
impl Formatter for RustFmt
sourcefn format_str(&self, source: impl AsRef<str>) -> Result<String, Error>
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 Read more
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 Read more
sourcefn format_tokens(&self, tokens: TokenStream) -> Result<String, Error>
fn format_tokens(&self, tokens: TokenStream) -> Result<String, Error>
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
impl RefUnwindSafe for RustFmt
impl Send for RustFmt
impl Sync for RustFmt
impl Unpin for RustFmt
impl UnwindSafe for RustFmt
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more