[−][src]Module genco::tokens
Utilities for working with token streams.
This is typically a module you will use if you intend to provide a manual implementation of FormatInto.
Examples
use genco::quote_in; use genco::tokens::{from_fn, ItemStr, FormatInto, static_literal}; use genco::lang::Lang; /// Format a block comment, starting with `/**`, and ending in `*/`. pub fn block_comment<I, L>(text: I) -> impl FormatInto<L> where I: IntoIterator, I::Item: Into<ItemStr>, L: Lang, { from_fn(move |t| { let mut it = text.into_iter().peekable(); if it.peek().is_some() { quote_in! { *t => #(static_literal("/**")) #(for line in it join (#<push>) { #<space>* #(line.into()) }) #<space>#(static_literal("*/")) } } }) } use genco::prelude::*; let tokens: java::Tokens = quote! { #(block_comment(&["This class is used for awesome stuff", "ok?"])) public static class Foo { } }; assert_eq!( vec![ "/**", " * This class is used for awesome stuff", " * ok?", " */", "public static class Foo {", "}" ], tokens.to_vec()? );
Structs
Display | Struct containing a type that implements Display and can be tokenized into a stream. |
FromFn | A captured function used for formatting tokens. |
QuotedFn | Struct containing a type that is quoted. |
RegisterFn | Struct containing a type only intended to be registered. |
Tokens | A stream of tokens. |
Enums
Item | A single item in a stream of tokens. |
ItemStr | A managed string that permits immutable borrowing. |
Traits
FormatInto | Trait for types that can be formatted in-place into a token stream. |
Register | Helper trait to convert something into a stream of registrations. |
Functions
display | Function to build a string literal. |
from_fn | Construct a formatter from a function. |
quoted | Function to provide string quoting. |
register | Function to provide item registration. |
static_literal | A formatter from a static literal. |