Struct syn::punctuated::Punctuated
source · pub struct Punctuated<T, P> { /* private fields */ }
Expand description
A punctuated sequence of syntax tree nodes of type T
separated by
punctuation of type P
.
Refer to the module documentation for details about punctuated sequences.
Implementations§
source§impl<T, P> Punctuated<T, P>
impl<T, P> Punctuated<T, P>
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Determines whether this punctuated sequence is empty, meaning it contains no syntax tree nodes or punctuation.
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of syntax tree nodes in this punctuated sequence.
This is the number of nodes of type T
, not counting the punctuation of
type P
.
sourcepub fn first_mut(&mut self) -> Option<&mut T>
pub fn first_mut(&mut self) -> Option<&mut T>
Mutably borrows the first element in this sequence.
sourcepub fn last_mut(&mut self) -> Option<&mut T>
pub fn last_mut(&mut self) -> Option<&mut T>
Mutably borrows the last element in this sequence.
sourcepub fn get_mut(&mut self, index: usize) -> Option<&mut T>
pub fn get_mut(&mut self, index: usize) -> Option<&mut T>
Mutably borrows the element at the given index.
sourcepub fn iter(&self) -> Iter<'_, T> ⓘ
pub fn iter(&self) -> Iter<'_, T> ⓘ
Returns an iterator over borrowed syntax tree nodes of type &T
.
sourcepub fn iter_mut(&mut self) -> IterMut<'_, T> ⓘ
pub fn iter_mut(&mut self) -> IterMut<'_, T> ⓘ
Returns an iterator over mutably borrowed syntax tree nodes of type
&mut T
.
sourcepub fn pairs(&self) -> Pairs<'_, T, P> ⓘ
pub fn pairs(&self) -> Pairs<'_, T, P> ⓘ
Returns an iterator over the contents of this sequence as borrowed punctuated pairs.
sourcepub fn pairs_mut(&mut self) -> PairsMut<'_, T, P> ⓘ
pub fn pairs_mut(&mut self) -> PairsMut<'_, T, P> ⓘ
Returns an iterator over the contents of this sequence as mutably borrowed punctuated pairs.
sourcepub fn into_pairs(self) -> IntoPairs<T, P> ⓘ
pub fn into_pairs(self) -> IntoPairs<T, P> ⓘ
Returns an iterator over the contents of this sequence as owned punctuated pairs.
sourcepub fn push_value(&mut self, value: T)
pub fn push_value(&mut self, value: T)
Appends a syntax tree node onto the end of this punctuated sequence. The sequence must already have a trailing punctuation, or be empty.
Use push
instead if the punctuated sequence may or may not already
have trailing punctuation.
§Panics
Panics if the sequence is nonempty and does not already have a trailing punctuation.
sourcepub fn push_punct(&mut self, punctuation: P)
pub fn push_punct(&mut self, punctuation: P)
Appends a trailing punctuation onto the end of this punctuated sequence. The sequence must be non-empty and must not already have trailing punctuation.
§Panics
Panics if the sequence is empty or already has a trailing punctuation.
sourcepub fn pop(&mut self) -> Option<Pair<T, P>>
pub fn pop(&mut self) -> Option<Pair<T, P>>
Removes the last punctuated pair from this sequence, or None
if the
sequence is empty.
sourcepub fn pop_punct(&mut self) -> Option<P>
pub fn pop_punct(&mut self) -> Option<P>
Removes the trailing punctuation from this punctuated sequence, or
None
if there isn’t any.
sourcepub fn trailing_punct(&self) -> bool
pub fn trailing_punct(&self) -> bool
Determines whether this punctuated sequence ends with a trailing punctuation.
sourcepub fn empty_or_trailing(&self) -> bool
pub fn empty_or_trailing(&self) -> bool
Returns true if either this Punctuated
is empty, or it has a trailing
punctuation.
Equivalent to punctuated.is_empty() || punctuated.trailing_punct()
.
sourcepub fn push(&mut self, value: T)where
P: Default,
pub fn push(&mut self, value: T)where
P: Default,
Appends a syntax tree node onto the end of this punctuated sequence.
If there is not a trailing punctuation in this sequence when this method
is called, the default value of punctuation type P
is inserted before
the given value of type T
.
sourcepub fn insert(&mut self, index: usize, value: T)where
P: Default,
pub fn insert(&mut self, index: usize, value: T)where
P: Default,
Inserts an element at position index
.
§Panics
Panics if index
is greater than the number of elements previously in
this punctuated sequence.
sourcepub fn parse_terminated(input: ParseStream<'_>) -> Result<Self>
pub fn parse_terminated(input: ParseStream<'_>) -> Result<Self>
Parses zero or more occurrences of T
separated by punctuation of type
P
, with optional trailing punctuation.
Parsing continues until the end of this parse stream. The entire content
of this parse stream must consist of T
and P
.
sourcepub fn parse_terminated_with(
input: ParseStream<'_>,
parser: fn(_: ParseStream<'_>) -> Result<T>,
) -> Result<Self>where
P: Parse,
pub fn parse_terminated_with(
input: ParseStream<'_>,
parser: fn(_: ParseStream<'_>) -> Result<T>,
) -> Result<Self>where
P: Parse,
Parses zero or more occurrences of T
using the given parse function,
separated by punctuation of type P
, with optional trailing
punctuation.
Like parse_terminated
, the entire content of this stream is expected
to be parsed.
sourcepub fn parse_separated_nonempty(input: ParseStream<'_>) -> Result<Self>
pub fn parse_separated_nonempty(input: ParseStream<'_>) -> Result<Self>
Parses one or more occurrences of T
separated by punctuation of type
P
, not accepting trailing punctuation.
Parsing continues as long as punctuation P
is present at the head of
the stream. This method returns upon parsing a T
and observing that it
is not followed by a P
, even if there are remaining tokens in the
stream.
sourcepub fn parse_separated_nonempty_with(
input: ParseStream<'_>,
parser: fn(_: ParseStream<'_>) -> Result<T>,
) -> Result<Self>
pub fn parse_separated_nonempty_with( input: ParseStream<'_>, parser: fn(_: ParseStream<'_>) -> Result<T>, ) -> Result<Self>
Parses one or more occurrences of T
using the given parse function,
separated by punctuation of type P
, not accepting trailing
punctuation.
Like parse_separated_nonempty
, may complete early without parsing
the entire content of this stream.
Trait Implementations§
source§impl<T, P> Clone for Punctuated<T, P>
impl<T, P> Clone for Punctuated<T, P>
source§impl<T, P> Default for Punctuated<T, P>
impl<T, P> Default for Punctuated<T, P>
source§impl<T, P> Extend<Pair<T, P>> for Punctuated<T, P>where
P: Default,
impl<T, P> Extend<Pair<T, P>> for Punctuated<T, P>where
P: Default,
source§fn extend<I: IntoIterator<Item = Pair<T, P>>>(&mut self, i: I)
fn extend<I: IntoIterator<Item = Pair<T, P>>>(&mut self, i: I)
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)source§impl<T, P> Extend<T> for Punctuated<T, P>where
P: Default,
impl<T, P> Extend<T> for Punctuated<T, P>where
P: Default,
source§fn extend<I: IntoIterator<Item = T>>(&mut self, i: I)
fn extend<I: IntoIterator<Item = T>>(&mut self, i: I)
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)source§impl<T, P> FromIterator<Pair<T, P>> for Punctuated<T, P>
impl<T, P> FromIterator<Pair<T, P>> for Punctuated<T, P>
source§impl<T, P> FromIterator<T> for Punctuated<T, P>where
P: Default,
impl<T, P> FromIterator<T> for Punctuated<T, P>where
P: Default,
source§fn from_iter<I: IntoIterator<Item = T>>(i: I) -> Self
fn from_iter<I: IntoIterator<Item = T>>(i: I) -> Self
source§impl<T, P> Index<usize> for Punctuated<T, P>
impl<T, P> Index<usize> for Punctuated<T, P>
source§impl<T, P> IndexMut<usize> for Punctuated<T, P>
impl<T, P> IndexMut<usize> for Punctuated<T, P>
source§impl<'a, T, P> IntoIterator for &'a Punctuated<T, P>
impl<'a, T, P> IntoIterator for &'a Punctuated<T, P>
source§impl<'a, T, P> IntoIterator for &'a mut Punctuated<T, P>
impl<'a, T, P> IntoIterator for &'a mut Punctuated<T, P>
source§impl<T, P> IntoIterator for Punctuated<T, P>
impl<T, P> IntoIterator for Punctuated<T, P>
source§impl<T, P> ToTokens for Punctuated<T, P>
impl<T, P> ToTokens for Punctuated<T, P>
source§fn to_tokens(&self, tokens: &mut TokenStream)
fn to_tokens(&self, tokens: &mut TokenStream)
source§fn to_token_stream(&self) -> TokenStream
fn to_token_stream(&self) -> TokenStream
source§fn into_token_stream(self) -> TokenStreamwhere
Self: Sized,
fn into_token_stream(self) -> TokenStreamwhere
Self: Sized,
Auto Trait Implementations§
impl<T, P> Freeze for Punctuated<T, P>
impl<T, P> RefUnwindSafe for Punctuated<T, P>where
T: RefUnwindSafe,
P: RefUnwindSafe,
impl<T, P> Send for Punctuated<T, P>
impl<T, P> Sync for Punctuated<T, P>
impl<T, P> Unpin for Punctuated<T, P>
impl<T, P> UnwindSafe for Punctuated<T, P>where
T: UnwindSafe,
P: UnwindSafe,
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> Spanned for Twhere
T: Spanned + ?Sized,
impl<T> Spanned for Twhere
T: Spanned + ?Sized,
source§fn span(&self) -> Span
fn span(&self) -> Span
Span
covering the complete contents of this syntax tree
node, or Span::call_site()
if this node is empty.