[][src]Struct genco::prelude::Tokens

pub struct Tokens<L = ()> where
    L: Lang
{ /* fields omitted */ }

A set of tokens.

Implementations

impl<L> Tokens<L> where
    L: Lang
[src]

Generic methods.

pub fn new() -> Tokens<L>[src]

Create a new set of tokens.

pub fn append<T>(&mut self, tokens: T) where
    T: FormatTokens<L>, 
[src]

Append the given element.

pub fn extend<I>(&mut self, it: I) where
    I: IntoIterator<Item = Item<L>>, 
[src]

Extend with another set of tokens.

pub fn walk_imports(&self) -> WalkImports<L>[src]

Walk over all elements.

pub fn register<T>(&mut self, tokens: T) where
    T: RegisterTokens<L>, 
[src]

Add an registered custom element that is not rendered.

Registration can be used to generate imports that do not render a visible result.

Examples

The register functionality is available through the quote! macro by using the register function.


use genco::rust::{imported, Config};
use genco::quote;

let write_bytes_ext = imported("byteorder", "WriteBytesExt").alias("_");

let tokens = quote!(#@(write_bytes_ext));

assert_eq!("use byteorder::WriteBytesExt as _;\n\n", tokens.to_file_string().unwrap());

pub fn is_empty(&self) -> bool[src]

Check if tokens contain no elements.

pub fn spacing(&mut self)[src]

Add a single spacing to the token stream.

pub fn push(&mut self)[src]

Add a single push spacing operation.

pub fn push_line(&mut self)[src]

Assert that there's the necessary elements to create one empty line at the top of the queue.

pub fn indent(&mut self)[src]

Add a single indentation to the token stream.

pub fn unindent(&mut self)[src]

Add a single unindentation to the token stream.

impl<L: Lang> Tokens<L>[src]

pub fn format(
    &self,
    out: &mut Formatter,
    config: &mut L::Config,
    level: usize
) -> Result
[src]

Format the tokens.

pub fn to_file_string_with(
    self,
    config: L::Config,
    format_config: FormatterConfig
) -> Result<String, Error>
[src]

Format the token stream as a file for the given target language to a string. Using the specified config.

pub fn to_string_with(
    self,
    config: L::Config,
    format_config: FormatterConfig
) -> Result<String, Error>
[src]

Format only the current token stream as a string. Using the specified config.

pub fn to_file_vec_with(
    self,
    config: L::Config,
    format_config: FormatterConfig
) -> Result<Vec<String>, Error>
[src]

Format tokens into a vector, where each entry equals a line in the resulting file. Using the specified config.

pub fn to_fmt_writer_with<W>(
    self,
    writer: W,
    config: L::Config,
    format_config: FormatterConfig
) -> Result<(), Error> where
    W: Write
[src]

Format the token stream as a file for the given target language to the given writer. Using the specified config.

pub fn to_io_writer_with<W>(
    self,
    writer: W,
    config: L::Config,
    format_config: FormatterConfig
) -> Result<(), Error> where
    W: Write
[src]

Format the token stream as a file for the given target language to the given writer. Using the specified config.

impl<C: Default, L: Lang<Config = C>> Tokens<L>[src]

pub fn to_file_string(self) -> Result<String, Error>[src]

Format the token stream as a file for the given target language to a string. Using the default configuration.

pub fn to_string(self) -> Result<String, Error>[src]

Format only the current token stream as a string. Using the default configuration.

pub fn to_file_vec(self) -> Result<Vec<String>, Error>[src]

Format tokens into a vector, where each entry equals a line in the resulting file. Using the default configuration.

pub fn to_fmt_writer<W>(self, writer: W) -> Result<(), Error> where
    W: Write
[src]

Format the token stream as a file for the given target language to the given writer. Using the default configuration.

pub fn to_io_writer<W>(self, writer: W) -> Result<(), Error> where
    W: Write
[src]

Format the token stream as a file for the given target language to the given writer. Using the default configuration.

Trait Implementations

impl<L> Clone for Tokens<L> where
    L: Lang
[src]

impl<L> Debug for Tokens<L> where
    L: Lang
[src]

impl<L: Default> Default for Tokens<L> where
    L: Lang
[src]

impl<L> FormatTokens<L> for Tokens<L> where
    L: Lang
[src]

impl<'a, L> FormatTokens<L> for &'a Tokens<L> where
    L: Lang
[src]

impl<'a, L> FromIterator<&'a Item<L>> for Tokens<L> where
    L: Lang
[src]

impl<L> FromIterator<Item<L>> for Tokens<L> where
    L: Lang
[src]

impl<L> IntoIterator for Tokens<L> where
    L: Lang
[src]

type Item = Item<L>

The type of the elements being iterated over.

type IntoIter = IntoIter<Item<L>>

Which kind of iterator are we turning this into?

Auto Trait Implementations

impl<L = ()> !RefUnwindSafe for Tokens<L>

impl<L = ()> !Send for Tokens<L>

impl<L = ()> !Sync for Tokens<L>

impl<L> Unpin for Tokens<L>

impl<L = ()> !UnwindSafe for Tokens<L>

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<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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.