pub struct VecWriter { /* private fields */ }
Expand description
Helper struct to format a token stream as a vector of strings.
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::VecWriter::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 vec = w.into_vec();
assert_eq!(
vec![
"let mut m = HashMap::new();",
"m.insert(1u32, 2u32);",
],
vec
);
Implementations
Trait Implementations
Writes a string slice into this writer, returning whether the write succeeded. Read more