Expand description
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 ($['\r']) {
$[' ']* $(line.into())
})
$[' ']$(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
A captured function used for formatting tokens.
Struct containing a type that is quoted.
Struct containing a type only intended to be registered.
A stream of tokens.
Enums
Traits
Trait for types that can be formatted in-place into a token stream.
Helper trait to convert something into a stream of registrations.
Functions
Function to build a string literal.
Construct a formatter from a function.
Function to provide string quoting.
Function to provide item registration.
A formatter from a static literal.