pub struct FmtWriter<W>where
W: Write,{ /* private fields */ }
Expand description
Helper struct to format a token stream to an underlying writer implementing fmt::Write.
§Examples
use genco::prelude::*;
use genco::fmt;
let map = rust::import("std::collections", "HashMap");
let tokens: rust::Tokens = quote! {
let mut m = $map::new();
m.insert(1u32, 2u32);
};
// Note: String implements std::fmt::Write
let mut w = fmt::FmtWriter::new(String::new());
let fmt = fmt::Config::from_lang::<Rust>();
let config = rust::Config::default();
// Default format state for Rust.
let format = rust::Format::default();
tokens.format(&mut w.as_formatter(&fmt), &config, &format)?;
let string = w.into_inner();
assert_eq!("let mut m = HashMap::new();\nm.insert(1u32, 2u32);", string);
Implementations§
Source§impl<W> FmtWriter<W>where
W: Write,
impl<W> FmtWriter<W>where
W: Write,
Sourcepub fn as_formatter<'a>(&'a mut self, config: &'a Config) -> Formatter<'a>
pub fn as_formatter<'a>(&'a mut self, config: &'a Config) -> Formatter<'a>
Convert into a formatter.
Sourcepub fn into_inner(self) -> W
pub fn into_inner(self) -> W
Convert into underlying writer.
Trait Implementations§
Auto Trait Implementations§
impl<W> Freeze for FmtWriter<W>where
W: Freeze,
impl<W> RefUnwindSafe for FmtWriter<W>where
W: RefUnwindSafe,
impl<W> Send for FmtWriter<W>where
W: Send,
impl<W> Sync for FmtWriter<W>where
W: Sync,
impl<W> Unpin for FmtWriter<W>where
W: Unpin,
impl<W> UnwindSafe for FmtWriter<W>where
W: UnwindSafe,
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