pub struct RustFmt { /* private fields */ }
Expand description
This formatter uses rustfmt
for formatting source code
An example using a custom configuration:
use rust_format::{Config, Edition, Formatter, RustFmt};
let source = r#"use std::marker; use std::io; mod test; mod impls;"#;
let mut config = Config::new_str()
.edition(Edition::Rust2018)
.option("reorder_imports", "false")
.option("reorder_modules", "false");
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§
Source§impl Formatter for RustFmt
impl Formatter for RustFmt
Source§fn 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 formattingSource§fn 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
Source§fn format_tokens(&self, tokens: TokenStream) -> Result<String, Error>
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 formattingAuto Trait Implementations§
impl Freeze for RustFmt
impl RefUnwindSafe for RustFmt
impl Send for RustFmt
impl Sync for RustFmt
impl Unpin for RustFmt
impl UnwindSafe for RustFmt
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more