[−][src]Struct genco::prelude::Tokens
A stream of tokens.
Structural Requirements
While not strictly necessary, this structure does its best to maintain so-called structural requirements.
That means the following:
- Only one [space()] may occur in sequence.
- Only one [push()] may occur in sequence.
- A [push()] may never be preceeded by a [line()], since it would have no effect.
- Every [line()] must be preceeded by a [push()].
use genco::{Tokens, Item}; let mut tokens = Tokens::<()>::new(); tokens.push(); tokens.push(); assert_eq!(vec![Item::Push::<()>], tokens);
Implementations
impl<L> Tokens<L> where
L: Lang,
[src]
L: Lang,
Generic methods.
pub fn new() -> Tokens<L>
[src]
Create a new set of tokens.
pub fn iter(&self) -> Iter<L>
[src]
Construct an iterator over this token stream.
pub fn into_iter(self) -> IntoIter<L>
[src]
Construct an iterator that owns all items in token stream.
pub fn append<T>(&mut self, tokens: T) where
T: FormatTokens<L>,
[src]
T: FormatTokens<L>,
Append the given element.
pub fn push_item(&mut self, item: Item<L>)
[src]
Append a single item to the stream, while checking for structural guarantees.
pub fn extend<I>(&mut self, it: I) where
I: IntoIterator<Item = Item<L>>,
[src]
I: IntoIterator<Item = Item<L>>,
Extend with another set of tokens.
This respects the structural requirements of adding one element at a time, like you would get by calling [space()], [push()], or [line()].
pub fn walk_imports(&self) -> WalkImports<L>
[src]
Walk over all imports.
Examples
use genco::prelude::*; let debug = rust::imported("std::fmt", "Debug"); let ty = rust::imported("std::collections", "HashMap") .with_arguments((rust::U32, debug.into_dyn())); let tokens = quote!(foo #ty baz); for import in tokens.walk_imports() { println!("{:?}", import); }
pub fn register<T>(&mut self, tokens: T) where
T: RegisterTokens<L>,
[src]
T: RegisterTokens<L>,
Add an registered custom element that is not rendered.
Registration can be used to generate imports that do not render a visible result.
Examples
The register
functionality is available through the quote! macro
by using the register function.
use genco::rust::{imported, Config}; use genco::quote; let write_bytes_ext = imported("byteorder", "WriteBytesExt").alias("_"); let tokens = quote!(#@(write_bytes_ext)); assert_eq!("use byteorder::WriteBytesExt as _;\n\n", tokens.to_file_string().unwrap());
pub fn is_empty(&self) -> bool
[src]
Check if tokens contain no items.
use genco::prelude::*; let tokens: Tokens<()> = quote!(); assert!(tokens.is_empty());
pub fn space(&mut self)
[src]
Add a single spacing to the token stream.
pub fn push(&mut self)
[src]
Add a single push spacing operation.
pub fn line(&mut self)
[src]
Assert that there's the necessary items to create one empty line at the end of the stream.
pub fn push_line(&mut self)
[src]
use line
function instead
Assert that there's the necessary items to create one empty line at the end of the stream.
pub fn indent(&mut self)
[src]
Add a single indentation to the token stream.
pub fn unindent(&mut self)
[src]
Add a single unindentation to the token stream.
pub fn format(
&self,
out: &mut Formatter,
config: &mut L::Config,
level: usize
) -> Result
[src]
&self,
out: &mut Formatter,
config: &mut L::Config,
level: usize
) -> Result
Format the tokens.
pub fn to_file_string_with(
self,
config: L::Config,
format_config: FormatterConfig
) -> Result<String, Error>
[src]
self,
config: L::Config,
format_config: FormatterConfig
) -> Result<String, Error>
Format the token stream as a file for the given target language to a
string. Using the specified config
.
pub fn to_string_with(
self,
config: L::Config,
format_config: FormatterConfig
) -> Result<String, Error>
[src]
self,
config: L::Config,
format_config: FormatterConfig
) -> Result<String, Error>
Format only the current token stream as a string. Using the specified
config
.
pub fn to_file_vec_with(
self,
config: L::Config,
format_config: FormatterConfig
) -> Result<Vec<String>, Error>
[src]
self,
config: L::Config,
format_config: FormatterConfig
) -> Result<Vec<String>, Error>
Format tokens into a vector, where each entry equals a line in the
resulting file. Using the specified config
.
pub fn to_fmt_writer_with<W>(
self,
writer: W,
config: L::Config,
format_config: FormatterConfig
) -> Result<(), Error> where
W: Write,
[src]
self,
writer: W,
config: L::Config,
format_config: FormatterConfig
) -> Result<(), Error> where
W: Write,
Format the token stream as a file for the given target language to the
given writer
. Using the specified config
.
pub fn to_io_writer_with<W>(
self,
writer: W,
config: L::Config,
format_config: FormatterConfig
) -> Result<(), Error> where
W: Write,
[src]
self,
writer: W,
config: L::Config,
format_config: FormatterConfig
) -> Result<(), Error> where
W: Write,
Format the token stream as a file for the given target language to the
given writer
. Using the specified config
.
impl<C: Default, L: Lang<Config = C>> Tokens<L>
[src]
pub fn to_file_string(self) -> Result<String, Error>
[src]
Format the token stream as a file for the given target language to a string. Using the default configuration.
pub fn to_string(self) -> Result<String, Error>
[src]
Format only the current token stream as a string. Using the default configuration.
pub fn to_file_vec(self) -> Result<Vec<String>, Error>
[src]
Format tokens into a vector, where each entry equals a line in the resulting file. Using the default configuration.
pub fn to_fmt_writer<W>(self, writer: W) -> Result<(), Error> where
W: Write,
[src]
W: Write,
Format the token stream as a file for the given target language to the given writer. Using the default configuration.
pub fn to_io_writer<W>(self, writer: W) -> Result<(), Error> where
W: Write,
[src]
W: Write,
Format the token stream as a file for the given target language to the given writer. Using the default configuration.
Trait Implementations
impl<L> Clone for Tokens<L> where
L: Lang,
[src]
L: Lang,
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<L> Debug for Tokens<L> where
L: Lang,
[src]
L: Lang,
impl<L: Default> Default for Tokens<L> where
L: Lang,
[src]
L: Lang,
impl<L> Eq for Tokens<L> where
L: Lang,
[src]
L: Lang,
impl<L> FormatTokens<L> for Tokens<L> where
L: Lang,
[src]
L: Lang,
fn format_tokens(self, tokens: &mut Self)
[src]
fn is_empty(&self) -> bool
[src]
fn into_tokens(self) -> Tokens<L> where
Self: Sized,
[src]
Self: Sized,
impl<'a, L> FormatTokens<L> for &'a Tokens<L> where
L: Lang,
[src]
L: Lang,
fn format_tokens(self, tokens: &mut Tokens<L>)
[src]
fn is_empty(&self) -> bool
[src]
fn into_tokens(self) -> Tokens<L> where
Self: Sized,
[src]
Self: Sized,
impl<'a, L: 'a> FromIterator<&'a Item<L>> for Tokens<L> where
L: Lang,
[src]
L: Lang,
fn from_iter<I: IntoIterator<Item = &'a Item<L>>>(iter: I) -> Tokens<L>
[src]
impl<L> FromIterator<Item<L>> for Tokens<L> where
L: Lang,
[src]
L: Lang,
fn from_iter<I: IntoIterator<Item = Item<L>>>(iter: I) -> Tokens<L>
[src]
impl<L> IntoIterator for Tokens<L> where
L: Lang,
[src]
L: Lang,
type Item = Item<L>
The type of the elements being iterated over.
type IntoIter = IntoIter<L>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<'a, L> IntoIterator for &'a Tokens<L> where
L: Lang,
[src]
L: Lang,
type Item = &'a Item<L>
The type of the elements being iterated over.
type IntoIter = Iter<'a, L>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<'a, L> PartialEq<[Item<L>]> for Tokens<L> where
L: Lang,
[src]
L: Lang,
impl<L> PartialEq<Tokens<L>> for Tokens<L> where
L: Lang,
[src]
L: Lang,
impl<'a, L> PartialEq<Tokens<L>> for Vec<Item<L>> where
L: Lang,
[src]
L: Lang,
impl<'a, L> PartialEq<Tokens<L>> for [Item<L>] where
L: Lang,
[src]
L: Lang,
impl<'a, L> PartialEq<Vec<Item<L>>> for Tokens<L> where
L: Lang,
[src]
L: Lang,
Auto Trait Implementations
impl<L = ()> !RefUnwindSafe for Tokens<L>
impl<L = ()> !Send for Tokens<L>
impl<L = ()> !Sync for Tokens<L>
impl<L> Unpin for Tokens<L>
impl<L = ()> !UnwindSafe for Tokens<L>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<I> IntoIterator for I where
I: Iterator,
[src]
I: Iterator,
type Item = <I as Iterator>::Item
The type of the elements being iterated over.
type IntoIter = I
Which kind of iterator are we turning this into?
fn into_iter(self) -> I
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,