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 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
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>
This is supported 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 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
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
🔬 This is a nightly-only experimental API. (
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more