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
sourceimpl<L> FormatInto<L> for Item<L> where
L: Lang,
impl<L> FormatInto<L> for Item<L> where
L: Lang,
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,
};
sourcefn format_into(self, tokens: &mut Tokens<L>)
fn format_into(self, tokens: &mut Tokens<L>)
Convert the type into tokens in-place. Read more
sourceimpl<'a, L> FromIterator<&'a Item<L>> for Tokens<L> where
L: Lang,
impl<'a, L> FromIterator<&'a Item<L>> for Tokens<L> where
L: Lang,
sourcefn from_iter<I: IntoIterator<Item = &'a Item<L>>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = &'a Item<L>>>(iter: I) -> Self
Creates a value from an iterator. Read more
sourceimpl<L> FromIterator<Item<L>> for Tokens<L> where
L: Lang,
impl<L> FromIterator<Item<L>> for Tokens<L> where
L: Lang,
sourcefn from_iter<I: IntoIterator<Item = Item<L>>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = Item<L>>>(iter: I) -> Self
Creates a value from an iterator. Read more
sourceimpl<L: Ord> Ord for Item<L> where
L: Lang,
L::Item: Ord,
L::Item: Ord,
impl<L: Ord> Ord for Item<L> where
L: Lang,
L::Item: Ord,
L::Item: Ord,
sourceimpl<L: PartialEq> PartialEq<Item<L>> for Item<L> where
L: Lang,
L::Item: PartialEq,
L::Item: PartialEq,
impl<L: PartialEq> PartialEq<Item<L>> for Item<L> where
L: Lang,
L::Item: PartialEq,
L::Item: PartialEq,
sourceimpl<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,
sourcefn partial_cmp(&self, other: &Item<L>) -> Option<Ordering>
fn partial_cmp(&self, other: &Item<L>) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl<L: Eq> Eq for Item<L> where
L: Lang,
L::Item: Eq,
L::Item: Eq,
impl<L> StructuralEq for Item<L> where
L: Lang,
impl<L> StructuralPartialEq for Item<L> where
L: Lang,
Auto Trait Implementations
impl<L> RefUnwindSafe for Item<L> where
<L as Lang>::Item: RefUnwindSafe,
impl<L> Send for Item<L> where
<L as Lang>::Item: Send,
impl<L> Sync for Item<L> where
<L as Lang>::Item: Sync,
impl<L> Unpin for Item<L>
impl<L> UnwindSafe for Item<L> where
<L as Lang>::Item: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more