pub trait ToTokens {
// Required method
fn to_tokens(&self, tokens: &mut TokenStream);
// Provided methods
fn to_token_iter(
&self,
) -> ShadowCountedIter<'_, <TokenStream as IntoIterator>::IntoIter> ⓘ { ... }
fn into_token_iter<'a>(
self,
) -> ShadowCountedIter<'a, <TokenStream as IntoIterator>::IntoIter> ⓘ
where Self: Sized { ... }
fn to_token_stream(&self) -> TokenStream { ... }
fn into_token_stream(self) -> TokenStream
where Self: Sized { ... }
fn tokens_to_string(&self) -> String { ... }
}Expand description
unsynn defines its own ToTokens trait to be able to implement it for std container types.
This is similar to the ToTokens from the quote crate but adds some extra methods and is
implemented for more types. Moreover the to_token_iter() method is the main entry point
for crating an iterator that can be used for parsing.
Required Methods§
Sourcefn to_tokens(&self, tokens: &mut TokenStream)
fn to_tokens(&self, tokens: &mut TokenStream)
Write &self to the given TokenStream.
Provided Methods§
Sourcefn to_token_iter(
&self,
) -> ShadowCountedIter<'_, <TokenStream as IntoIterator>::IntoIter> ⓘ
fn to_token_iter( &self, ) -> ShadowCountedIter<'_, <TokenStream as IntoIterator>::IntoIter> ⓘ
Convert &self into a TokenIter object.
Sourcefn into_token_iter<'a>(
self,
) -> ShadowCountedIter<'a, <TokenStream as IntoIterator>::IntoIter> ⓘwhere
Self: Sized,
fn into_token_iter<'a>(
self,
) -> ShadowCountedIter<'a, <TokenStream as IntoIterator>::IntoIter> ⓘwhere
Self: Sized,
Convert self into a TokenIter object.
Sourcefn to_token_stream(&self) -> TokenStream
fn to_token_stream(&self) -> TokenStream
Convert &self into a TokenStream object.
Sourcefn into_token_stream(self) -> TokenStreamwhere
Self: Sized,
fn into_token_stream(self) -> TokenStreamwhere
Self: Sized,
Convert self into a TokenStream object.
Sourcefn tokens_to_string(&self) -> String
fn tokens_to_string(&self) -> String
Trait Implementations§
Implementations on Foreign Types§
Source§impl ToTokens for &str
Tokenizes a &str. Panics if the input string does not tokenize.
impl ToTokens for &str
Tokenizes a &str. Panics if the input string does not tokenize.
§Example
let mut tokens = "foo -> {1,2,3}".to_token_stream();
assert_eq!(
tokens.to_string(),
"foo -> { 1 , 2 , 3 }"
);fn to_tokens(&self, tokens: &mut TokenStream)
Source§impl ToTokens for i8
Emit a literal i8 with negative sign and without suffix
impl ToTokens for i8
Emit a literal i8 with negative sign and without suffix
fn to_tokens(&self, tokens: &mut TokenStream)
Source§impl ToTokens for i16
Emit a literal i16 with negative sign and without suffix
impl ToTokens for i16
Emit a literal i16 with negative sign and without suffix
fn to_tokens(&self, tokens: &mut TokenStream)
Source§impl ToTokens for i32
Emit a literal i32 with negative sign and without suffix
impl ToTokens for i32
Emit a literal i32 with negative sign and without suffix
fn to_tokens(&self, tokens: &mut TokenStream)
Source§impl ToTokens for i64
Emit a literal i64 with negative sign and without suffix
impl ToTokens for i64
Emit a literal i64 with negative sign and without suffix
fn to_tokens(&self, tokens: &mut TokenStream)
Source§impl ToTokens for i128
Emit a literal i128 with negative sign and without suffix
impl ToTokens for i128
Emit a literal i128 with negative sign and without suffix
fn to_tokens(&self, tokens: &mut TokenStream)
Source§impl ToTokens for isize
Emit a literal isize with negative sign and without suffix
impl ToTokens for isize
Emit a literal isize with negative sign and without suffix
fn to_tokens(&self, tokens: &mut TokenStream)
Source§impl ToTokens for u8
Emit a literal u8 without sign and suffix
impl ToTokens for u8
Emit a literal u8 without sign and suffix
fn to_tokens(&self, tokens: &mut TokenStream)
Source§impl ToTokens for u16
Emit a literal u16 without sign and suffix
impl ToTokens for u16
Emit a literal u16 without sign and suffix
fn to_tokens(&self, tokens: &mut TokenStream)
Source§impl ToTokens for u32
Emit a literal u32 without sign and suffix
impl ToTokens for u32
Emit a literal u32 without sign and suffix
fn to_tokens(&self, tokens: &mut TokenStream)
Source§impl ToTokens for u64
Emit a literal u64 without sign and suffix
impl ToTokens for u64
Emit a literal u64 without sign and suffix
fn to_tokens(&self, tokens: &mut TokenStream)
Source§impl ToTokens for u128
Emit a literal u128 without sign and suffix
impl ToTokens for u128
Emit a literal u128 without sign and suffix
fn to_tokens(&self, tokens: &mut TokenStream)
Source§impl ToTokens for usize
Emit a literal usize without sign and suffix
impl ToTokens for usize
Emit a literal usize without sign and suffix