[][src]Struct genco::fmt::FmtWriter

pub struct FmtWriter<W> where
    W: Write
{ /* fields omitted */ }

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

impl<W> FmtWriter<W> where
    W: Write
[src]

pub fn new(writer: W) -> Self[src]

Construct a new line writer from the underlying writer.

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

Convert into a formatter.

pub fn into_inner(self) -> W[src]

Convert into underlying writer.

Trait Implementations

impl<W> Write for FmtWriter<W> where
    W: Write
[src]

Auto Trait Implementations

impl<W> RefUnwindSafe for FmtWriter<W> where
    W: RefUnwindSafe

impl<W> Send for FmtWriter<W> where
    W: Send

impl<W> Sync for FmtWriter<W> where
    W: Sync

impl<W> Unpin for FmtWriter<W> where
    W: Unpin

impl<W> UnwindSafe for FmtWriter<W> where
    W: UnwindSafe

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.