pub struct TokenStream { /* private fields */ }
Expand description
A sequence of tokens.
This is the return type of
Group::token_stream
, and can be created
from a proc_macro::TokenStream
or
proc_macro2::TokenStream
.
Implementations§
Source§impl TokenStream
impl TokenStream
Sourcepub fn prepare_whitespace(&mut self)
pub fn prepare_whitespace(&mut self)
Removes all whitespace that doesn’t come at the start of a line.
Note that the parse*
functions remove all whitespace.
Sourcepub fn remove_blank_space(&mut self)
pub fn remove_blank_space(&mut self)
Removes all non-newline whitespace from self
.
Note that the parse*
functions will remove all whitespace.
Sourcepub fn remove_whitespace(&mut self)
pub fn remove_whitespace(&mut self)
Removes all whitespace tokens from this stream.
This method is automatically called by the parse*
functions.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if there are no tokens in self
.
Examples found in repository?
examples/lox/main.rs (line 439)
433 fn parse(input: ParseStream) -> Result<Self> {
434 let name: Ident = input.parse()?;
435 let mut contents: Group<Parentheses> = input.parse()?;
436 contents.remove_whitespace();
437 let Parentheses(span) = contents.delimiters();
438 let tokens = contents.into_token_stream();
439 let params: Vec<Ident> = if tokens.is_empty() {
440 vec![]
441 } else {
442 let params: Punctuated<Ident, Punct![","]> =
443 Punctuated::parse_separated.parse(tokens)?;
444 params.into_iter().collect()
445 };
446 if params.len() >= 255 {
447 input.add_error(input.new_error(
448 "Can't have more than 254 parameters".to_string(),
449 span,
450 error_codes::TOO_MANY_ARGS,
451 ));
452 }
453 let mut contents: Group<Braces> = input.parse()?;
454 contents.remove_whitespace();
455 let body = block.parse(contents.into_token_stream())?;
456 Ok(Function { name, params, body })
457 }
Sourcepub fn append(&mut self, other: &mut TokenStream)
pub fn append(&mut self, other: &mut TokenStream)
Add another TokenStream
to the end of self
.
Trait Implementations§
Source§impl Clone for TokenStream
impl Clone for TokenStream
Source§fn clone(&self) -> TokenStream
fn clone(&self) -> TokenStream
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for TokenStream
impl Debug for TokenStream
Source§impl Display for TokenStream
impl Display for TokenStream
Source§impl<A: ToTokens> Extend<A> for TokenStream
impl<A: ToTokens> Extend<A> for TokenStream
Source§fn extend<T: IntoIterator<Item = A>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = A>>(&mut self, iter: T)
Extends a collection with the contents of an iterator. Read more
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one
)Extends a collection with exactly one element.
Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Source§impl<'a> From<&'a TokenStream> for ParseBuffer<'a>
impl<'a> From<&'a TokenStream> for ParseBuffer<'a>
Source§fn from(value: &'a TokenStream) -> Self
fn from(value: &'a TokenStream) -> Self
Converts to this type from the input type.
Source§impl<'a> From<TokenStream> for ParseBuffer<'a>
impl<'a> From<TokenStream> for ParseBuffer<'a>
Source§fn from(value: TokenStream) -> Self
fn from(value: TokenStream) -> Self
Converts to this type from the input type.
Source§impl From<TokenStream> for TokenStream
Available on crate features proc-macro
and proc-macro2
only.
impl From<TokenStream> for TokenStream
Available on crate features
proc-macro
and proc-macro2
only.Source§fn from(value: TokenStream) -> Self
fn from(value: TokenStream) -> Self
Converts to this type from the input type.
Source§impl From<TokenStream> for TokenStream
Available on crate feature proc-macro2
only.
impl From<TokenStream> for TokenStream
Available on crate feature
proc-macro2
only.Source§fn from(value: TokenStream2) -> Self
fn from(value: TokenStream2) -> Self
Converts to this type from the input type.
Source§impl Hash for TokenStream
impl Hash for TokenStream
Source§impl PartialEq for TokenStream
impl PartialEq for TokenStream
Source§impl PartialOrd for TokenStream
impl PartialOrd for TokenStream
Source§impl ToTokens for TokenStream
impl ToTokens for TokenStream
Source§fn to_tokens(&self, tokens: &mut TokenStream)
fn to_tokens(&self, tokens: &mut TokenStream)
Append
self
to the given TokenStream
.Source§fn to_token_stream(&self) -> TokenStream
fn to_token_stream(&self) -> TokenStream
Convert
self
directly into a TokenStream
.Source§fn into_token_stream(self) -> TokenStreamwhere
Self: Sized,
fn into_token_stream(self) -> TokenStreamwhere
Self: Sized,
Convert
self
directly into a TokenStream
.Source§impl ToTokens for TokenStream
Available on crate feature proc-macro2
only.
impl ToTokens for TokenStream
Available on crate feature
proc-macro2
only.Source§fn to_tokens(&self, tokens: &mut TokenStream2)
fn to_tokens(&self, tokens: &mut TokenStream2)
Source§fn to_token_stream(&self) -> TokenStream2
fn to_token_stream(&self) -> TokenStream2
Source§fn into_token_stream(self) -> TokenStream2
fn into_token_stream(self) -> TokenStream2
Source§impl<'a> TryFrom<&'a TokenStream> for TokenStream
Available on crate feature proc-macro2
only.
impl<'a> TryFrom<&'a TokenStream> for TokenStream
Available on crate feature
proc-macro2
only.Source§impl TryFrom<Arc<SourceFile>> for TokenStream
impl TryFrom<Arc<SourceFile>> for TokenStream
Source§impl TryFrom<TokenStream> for TokenStream
Available on crate feature proc-macro2
only.
impl TryFrom<TokenStream> for TokenStream
Available on crate feature
proc-macro2
only.impl StructuralPartialEq for TokenStream
Auto Trait Implementations§
impl Freeze for TokenStream
impl RefUnwindSafe for TokenStream
impl Send for TokenStream
impl Sync for TokenStream
impl Unpin for TokenStream
impl UnwindSafe for TokenStream
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more