[−][src]Struct genco::Tokens
A set of tokens.
Implementations
impl<'el, L> Tokens<'el, L> where
L: Lang,
[src]
L: Lang,
Generic methods.
pub fn new() -> Tokens<'el, L>
[src]
Create a new set of tokens.
pub fn nested<T>(&mut self, tokens: T) where
T: FormatTokens<'el, L>,
[src]
T: FormatTokens<'el, L>,
Push a nested definition.
pub fn nested_into<B>(&mut self, builder: B) where
B: FnOnce(&mut Tokens<'el, L>),
[src]
B: FnOnce(&mut Tokens<'el, L>),
Push a nested definition.
pub fn try_nested_into<E, B>(&mut self, builder: B) -> Result<(), E> where
B: FnOnce(&mut Tokens<'el, L>) -> Result<(), E>,
[src]
B: FnOnce(&mut Tokens<'el, L>) -> Result<(), E>,
Push a nested definition.
This is a fallible version that expected the builder to return a result.
pub fn nested_ref(&mut self, tokens: &'el Tokens<'el, L>)
[src]
Push a nested reference to a definition.
pub fn push<T>(&mut self, tokens: T) where
T: FormatTokens<'el, L>,
[src]
T: FormatTokens<'el, L>,
Push a definition, guaranteed to be preceded with one newline.
pub fn push_into<B>(&mut self, builder: B) where
B: FnOnce(&mut Tokens<'el, L>),
[src]
B: FnOnce(&mut Tokens<'el, L>),
Push a new created definition, guaranteed to be preceded with one newline.
pub fn try_push_into<E, B>(&mut self, builder: B) -> Result<(), E> where
B: FnOnce(&mut Tokens<'el, L>) -> Result<(), E>,
[src]
B: FnOnce(&mut Tokens<'el, L>) -> Result<(), E>,
Push a new created definition, guaranteed to be preceded with one newline.
This is a fallible version that expected the builder to return a result.
pub fn push_unless_empty<T>(&mut self, tokens: T) where
T: FormatTokens<'el, L>,
[src]
T: FormatTokens<'el, L>,
Push the given set of tokens, unless it is empty.
This is useful when you wish to preserve the structure of nested and joined tokens.
pub fn insert<E>(&mut self, pos: usize, element: E) where
E: Into<Element<'el, L>>,
[src]
E: Into<Element<'el, L>>,
Insert the given element.
pub fn append<T>(&mut self, tokens: T) where
T: FormatTokens<'el, L>,
[src]
T: FormatTokens<'el, L>,
Append the given element.
pub fn append_ref(&mut self, element: &'el Element<'el, L>)
[src]
Append a reference to a definition.
pub fn append_unless_empty<T>(&mut self, tokens: T) where
T: FormatTokens<'el, L>,
[src]
T: FormatTokens<'el, L>,
Append the given set of tokens, unless it is empty.
This is useful when you wish to preserve the structure of nested and joined tokens.
pub fn extend<I>(&mut self, it: I) where
I: IntoIterator<Item = Element<'el, L>>,
[src]
I: IntoIterator<Item = Element<'el, L>>,
Extend with another set of tokens.
pub fn walk_custom(&self) -> WalkCustom<'_, 'el, L>
[src]
Walk over all elements.
pub fn register(&mut self, custom: impl Into<LangBox<'el, L>>)
[src]
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 as
@<stmt>
.
#![feature(proc_macro_hygiene)] 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 elements.
pub fn spacing(&mut self)
[src]
Add a single spacing to the token stream.
pub fn line_spacing(&mut self)
[src]
Add a single line spacing to the token stream.
pub fn push_spacing(&mut self)
[src]
Add a single push spacing operation.
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.
impl<'el, L: Lang> Tokens<'el, L>
[src]
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<'el, C: Default, L: Lang<Config = C>> Tokens<'el, 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<'el, L> Clone for Tokens<'el, L> where
L: Lang,
[src]
L: Lang,
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<'el, L: Debug> Debug for Tokens<'el, L> where
L: Lang,
[src]
L: Lang,
impl<'el, L: Default> Default for Tokens<'el, L> where
L: Lang,
[src]
L: Lang,
impl<'el, L> FormatTokens<'el, L> for Tokens<'el, L> where
L: Lang,
[src]
L: Lang,
impl<'el, L> FromIterator<&'el Element<'el, L>> for Tokens<'el, L> where
L: Lang,
[src]
L: Lang,
fn from_iter<I: IntoIterator<Item = &'el Element<'el, L>>>(
iter: I
) -> Tokens<'el, L>
[src]
iter: I
) -> Tokens<'el, L>
impl<'el, L> FromIterator<Element<'el, L>> for Tokens<'el, L> where
L: Lang,
[src]
L: Lang,
fn from_iter<I: IntoIterator<Item = Element<'el, L>>>(iter: I) -> Tokens<'el, L>
[src]
impl<'el, L> IntoIterator for Tokens<'el, L> where
L: Lang,
[src]
L: Lang,
Auto Trait Implementations
impl<'el, L> !RefUnwindSafe for Tokens<'el, L>
impl<'el, L> !Send for Tokens<'el, L>
impl<'el, L> !Sync for Tokens<'el, L>
impl<'el, L> Unpin for Tokens<'el, L>
impl<'el, L> !UnwindSafe for Tokens<'el, 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>,