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

Construct a new line writer from the underlying writer.

Convert into a formatter.

Convert into underlying writer.

Trait Implementations

Writes a char into this writer, returning whether the write succeeded. Read more

Writes a string slice into this writer, returning whether the write succeeded. Read more

Glue for usage of the write! macro with implementors of this trait. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.