[][src]Struct genco::Tokens

pub struct Tokens<'el, L> where
    L: Lang
{ /* fields omitted */ }

A set of tokens.

Implementations

impl<'el, L> Tokens<'el, L> where
    L: Lang
[src]

Generic methods.

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

Create a new set of tokens.

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

Push a nested definition.

pub fn nested_into<B>(&mut self, builder: B) where
    B: FnOnce(&mut Tokens<'el, L>), 
[src]

Push a nested definition.

pub fn try_nested_into<E, B>(&mut self, builder: B) -> Result<(), E> where
    B: FnOnce(&mut Tokens<'el, L>) -> Result<(), E>, 
[src]

Push a nested definition.

This is a fallible version that expected the builder to return a result.

pub fn nested_ref(&mut self, tokens: &'el Tokens<'el, L>)[src]

Push a nested reference to a definition.

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

Push a definition, guaranteed to be preceded with one newline.

pub fn push_into<B>(&mut self, builder: B) where
    B: FnOnce(&mut Tokens<'el, L>), 
[src]

Push a new created definition, guaranteed to be preceded with one newline.

pub fn try_push_into<E, B>(&mut self, builder: B) -> Result<(), E> where
    B: FnOnce(&mut Tokens<'el, L>) -> Result<(), E>, 
[src]

Push a new created definition, guaranteed to be preceded with one newline.

This is a fallible version that expected the builder to return a result.

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

Push the given set of tokens, unless it is empty.

This is useful when you wish to preserve the structure of nested and joined tokens.

pub fn insert<E>(&mut self, pos: usize, element: E) where
    E: Into<Element<'el, L>>, 
[src]

Insert the given element.

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

Append the given element.

pub fn append_ref(&mut self, element: &'el Element<'el, L>)[src]

Append a reference to a definition.

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

Append the given set of tokens, unless it is empty.

This is useful when you wish to preserve the structure of nested and joined tokens.

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

Extend with another set of tokens.

pub fn walk_custom(&self) -> WalkCustom<'_, 'el, L>[src]

Walk over all elements.

pub fn register(&mut self, custom: impl Into<LangBox<'el, 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 as @<stmt>.

#![feature(proc_macro_hygiene)]

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 line_spacing(&mut self)[src]

Add a single line spacing to the token stream.

pub fn push_spacing(&mut self)[src]

Add a single push spacing operation.

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<'el, L: Lang> Tokens<'el, 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<'el, C: Default, L: Lang<Config = C>> Tokens<'el, 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<'el, L> Clone for Tokens<'el, L> where
    L: Lang
[src]

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

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

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

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

impl<'el, L> FromIterator<Element<'el, L>> for Tokens<'el, L> where
    L: Lang
[src]

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

type Item = Element<'el, L>

The type of the elements being iterated over.

type IntoIter = IntoIter<Element<'el, L>>

Which kind of iterator are we turning this into?

Auto Trait Implementations

impl<'el, L> !RefUnwindSafe for Tokens<'el, L>

impl<'el, L> !Send for Tokens<'el, L>

impl<'el, L> !Sync for Tokens<'el, L>

impl<'el, L> Unpin for Tokens<'el, L>

impl<'el, L> !UnwindSafe for Tokens<'el, 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.