[][src]Struct genco::fmt::IoWriter

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

Helper struct to format a token stream to an underlying writer implementing io::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);
};

// Vec<u8> implements std::io::Write
let mut w = fmt::IoWriter::new(Vec::<u8>::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 vector = w.into_inner();
let string = std::str::from_utf8(&vector)?;

assert_eq!("let mut m = HashMap::new();\nm.insert(1u32, 2u32);", string);

Implementations

impl<W> IoWriter<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 the inner writer.

Trait Implementations

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

Auto Trait Implementations

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

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

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

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

impl<W> UnwindSafe for IoWriter<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.