pub enum Item<L> where
    L: Lang
{ Literal(ItemStr), Lang(usizeBox<L::Item>), Register(usizeBox<L::Item>), Push, Line, Space, Indentation(i16), OpenQuote(bool), CloseQuote, OpenEval, CloseEval, }
Expand description

A single item in a stream of tokens.

Variants

Literal(ItemStr)

A literal item. Is added as a raw string to the stream of tokens.

Lang(usizeBox<L::Item>)

A language-specific item.

Register(usizeBox<L::Item>)

A language-specific item that is not rendered.

Push

Push a new line unless the current line is empty. Will be flushed on indentation changes.

Line

Push a line. Will be flushed on indentation changes.

Space

Space between language items. Typically a single space.

Multiple spacings in sequence are collapsed into one. A spacing does nothing if at the beginning of a line.

Indentation(i16)

Manage indentation.

An indentation of 0 has no effect.

OpenQuote(bool)

Switch to handling input as a quote.

The argument indicates whether the string contains any interpolated values.

The string content is quoted with the language-specific [quoting method]. [quoting method]: Lang::Openquote_string

CloseQuote

Close the current quote.

OpenEval

Switch on evaluation. Only valid during string handling.

CloseEval

Close evaluation.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formatting an item is the same as adding said item to the token stream through item().

Examples

use genco::prelude::*;
use genco::tokens::{Item, ItemStr};

let foo = Item::Literal(ItemStr::Static("foo"));
let bar = Item::Literal(ItemStr::Box("bar".into()));

let result: Tokens = quote!(#foo #bar baz);

assert_eq!("foo bar baz", result.to_string()?);

assert_eq!{
    vec![
        Item::Literal(ItemStr::Static("foo")),
        Item::Space,
        Item::Literal(ItemStr::Box("bar".into())),
        Item::Space,
        Item::Literal(ItemStr::Static("baz")),
    ] as Vec<Item<()>>,
    result,
};

Convert the type into tokens in-place. Read more

Creates a value from an iterator. Read more

Creates a value from an iterator. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. 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 resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

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.