pub struct IoWriter<W>where
W: Write,{ /* private fields */ }
Expand description
Helper struct to format a token stream to an underlying writer implementing io::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);
};
// Vec<u8> implements std::io::Write
let mut w = fmt::IoWriter::new(Vec::<u8>::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 vector = w.into_inner();
let string = std::str::from_utf8(&vector)?;
assert_eq!("let mut m = HashMap::new();\nm.insert(1u32, 2u32);", string);
Implementations§
Source§impl<W> IoWriter<W>where
W: Write,
impl<W> IoWriter<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 the inner writer.
Trait Implementations§
Auto Trait Implementations§
impl<W> Freeze for IoWriter<W>where
W: Freeze,
impl<W> RefUnwindSafe for IoWriter<W>where
W: RefUnwindSafe,
impl<W> Send for IoWriter<W>where
W: Send,
impl<W> Sync for IoWriter<W>where
W: Sync,
impl<W> Unpin for IoWriter<W>where
W: Unpin,
impl<W> UnwindSafe for IoWriter<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