[][src]Struct genco::fmt::VecWriter

pub struct VecWriter { /* fields omitted */ }

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

impl VecWriter[src]

pub fn new() -> Self[src]

Construct a new writer to a vector.

pub fn as_formatter<'a>(&'a mut self, config: &'a Config) -> Formatter<'a>[src]

Convert into a formatter.

pub fn into_vec(self) -> Vec<String>[src]

Convert into a vector.

Trait Implementations

impl Default for VecWriter[src]

impl Write for VecWriter[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.