pub enum Item<L> where
L: Lang, {
Literal(ItemStr),
Lang(usize, Box<L::Item>),
Register(usize, Box<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(usize, Box<L::Item>)
A language-specific item.
Register(usize, Box<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
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
impl<L: PartialOrd> PartialOrd<Item<L>> for Item<L> where
L: Lang,
L::Item: PartialOrd,
L::Item: PartialOrd,
impl<L: PartialOrd> PartialOrd<Item<L>> for Item<L> where
L: Lang,
L::Item: PartialOrd,
L::Item: PartialOrd,
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
Auto Trait Implementations
impl<L> RefUnwindSafe for Item<L> where
<L as Lang>::Item: RefUnwindSafe,
impl<L> UnwindSafe for Item<L> where
<L as Lang>::Item: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more