Struct rust_format::PrettyPlease
source · [−]pub struct PrettyPlease;
Expand description
This formatter uses prettyplease for formatting source code
From string:
use rust_format::{Formatter, PrettyPlease};
let source = r#"fn main() { println!("Hello World!"); }"#;
let actual = PrettyPlease.format_str(source).unwrap();
let expected = r#"fn main() {
println!("Hello World!");
}
"#;
assert_eq!(expected, actual);
From token stream:
use quote::quote;
use rust_format::{Formatter, PrettyPlease};
let source = quote! { fn main() { println!("Hello World!"); } };
let actual = PrettyPlease.format_tokens(source).unwrap();
let expected = r#"fn main() {
println!("Hello World!");
}
"#;
assert_eq!(expected, actual);
Trait Implementations
sourceimpl Formatter for PrettyPlease
impl Formatter for PrettyPlease
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_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 PrettyPlease
impl Send for PrettyPlease
impl Sync for PrettyPlease
impl Unpin for PrettyPlease
impl UnwindSafe for PrettyPlease
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