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
Convert into a formatter.
Convert into underlying writer.
Trait Implementations
Writes a string slice into this writer, returning whether the write succeeded. Read more