Struct parsel::ast::Punctuated
source · [−]pub struct Punctuated<T, P> { /* private fields */ }
Expand description
Parses a given production repeatedly, separated by punctuation.
Optional trailing punctuation is allowed, and the entire token
stream must consist of interleaved representations of T
and P
.
(Thus, this is generally only useful within a delimited group.)
let items: Punctuated<Lit, Token![,]> = parse_quote!(44, true, "str liter", 5.55,);
let items: Vec<Lit> = items.into_iter().collect();
assert_eq!(items, [
Lit::from(44_u128),
Lit::from(true),
Lit::from("str liter"),
Lit::try_from(5.55).unwrap(),
]);
Implementations
sourceimpl<T, P> Punctuated<T, P>
impl<T, P> Punctuated<T, P>
pub const fn new() -> Self
pub fn is_empty(&self) -> bool
pub fn len(&self) -> usize
pub fn into_inner(self) -> Punctuated<T, P>
pub fn iter(&self) -> Iter<'_, T>
pub fn iter_mut(&mut self) -> IterMut<'_, T>
pub fn into_pairs(self) -> IntoPairs<T, P>
pub fn pairs(&self) -> Pairs<'_, T, P>
pub fn pairs_mut(&mut self) -> PairsMut<'_, T, P>
Methods from Deref<Target = 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 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 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 previously have a trailing punctuation.
Use push
instead if the punctuated sequence may or may not already
have trailing punctuation.
Panics
Panics if the sequence does not already have a trailing punctuation when this method is called.
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 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
.
Trait Implementations
sourceimpl<T, P> AsMut<Punctuated<T, P>> for Punctuated<T, P>
impl<T, P> AsMut<Punctuated<T, P>> for Punctuated<T, P>
sourcefn as_mut(&mut self) -> &mut Punctuated<T, P>
fn as_mut(&mut self) -> &mut Punctuated<T, P>
Converts this type into a mutable reference of the (usually inferred) input type.
sourceimpl<T, P> AsRef<Punctuated<T, P>> for Punctuated<T, P>
impl<T, P> AsRef<Punctuated<T, P>> for Punctuated<T, P>
sourcefn as_ref(&self) -> &Punctuated<T, P>
fn as_ref(&self) -> &Punctuated<T, P>
Converts this type into a shared reference of the (usually inferred) input type.
sourceimpl<T, P> Borrow<Punctuated<T, P>> for Punctuated<T, P>
impl<T, P> Borrow<Punctuated<T, P>> for Punctuated<T, P>
sourcefn borrow(&self) -> &Punctuated<T, P>
fn borrow(&self) -> &Punctuated<T, P>
Immutably borrows from an owned value. Read more
sourceimpl<T, P> BorrowMut<Punctuated<T, P>> for Punctuated<T, P>
impl<T, P> BorrowMut<Punctuated<T, P>> for Punctuated<T, P>
sourcefn borrow_mut(&mut self) -> &mut Punctuated<T, P>
fn borrow_mut(&mut self) -> &mut Punctuated<T, P>
Mutably borrows from an owned value. Read more
sourceimpl<T: Clone, P: Clone> Clone for Punctuated<T, P>
impl<T: Clone, P: Clone> Clone for Punctuated<T, P>
sourcefn clone(&self) -> Punctuated<T, P>
fn clone(&self) -> Punctuated<T, P>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<T, P> Debug for Punctuated<T, P> where
T: Debug,
P: Debug,
impl<T, P> Debug for Punctuated<T, P> where
T: Debug,
P: Debug,
sourceimpl<T, P> Default for Punctuated<T, P>
impl<T, P> Default for Punctuated<T, P>
sourceimpl<T, P> Deref for Punctuated<T, P>
impl<T, P> Deref for Punctuated<T, P>
type Target = Punctuated<T, P>
type Target = Punctuated<T, P>
The resulting type after dereferencing.
sourceimpl<T, P> DerefMut for Punctuated<T, P>
impl<T, P> DerefMut for Punctuated<T, P>
sourceimpl<T, P> Display for Punctuated<T, P> where
T: ToTokens,
P: ToTokens,
impl<T, P> Display for Punctuated<T, P> where
T: ToTokens,
P: ToTokens,
sourceimpl<T, P> Extend<Pair<T, P>> for Punctuated<T, P>
impl<T, P> Extend<Pair<T, P>> for Punctuated<T, P>
sourcefn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = Pair<T, P>>,
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = Pair<T, P>>,
Extends a collection with the contents of an iterator. Read more
sourcefn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Extends a collection with exactly one element.
sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
sourceimpl<T, P> Extend<T> for Punctuated<T, P> where
P: Default,
impl<T, P> Extend<T> for Punctuated<T, P> where
P: Default,
sourcefn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = T>,
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = T>,
Extends a collection with the contents of an iterator. Read more
sourcefn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Extends a collection with exactly one element.
sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
sourceimpl<T, P> From<Punctuated<T, P>> for Punctuated<T, P>
impl<T, P> From<Punctuated<T, P>> for Punctuated<T, P>
sourcefn from(inner: Punctuated<T, P>) -> Self
fn from(inner: Punctuated<T, P>) -> Self
Converts to this type from the input type.
sourceimpl<T, P> From<Punctuated<T, P>> for Punctuated<T, P>
impl<T, P> From<Punctuated<T, P>> for Punctuated<T, P>
sourcefn from(punctuated: Punctuated<T, P>) -> Self
fn from(punctuated: Punctuated<T, P>) -> Self
Converts to this type from the input type.
sourceimpl<T, P> FromIterator<Pair<T, P>> for Punctuated<T, P>
impl<T, P> FromIterator<Pair<T, P>> for Punctuated<T, P>
sourcefn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = Pair<T, P>>,
fn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = Pair<T, P>>,
Creates a value from an iterator. Read more
sourceimpl<T, P> FromIterator<T> for Punctuated<T, P> where
P: Default,
impl<T, P> FromIterator<T> for Punctuated<T, P> where
P: Default,
sourcefn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = T>,
fn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = T>,
Creates a value from an iterator. Read more
sourceimpl<T, P> FromStr for Punctuated<T, P> where
T: Parse,
P: Parse,
impl<T, P> FromStr for Punctuated<T, P> where
T: Parse,
P: Parse,
sourceimpl<T: Hash, P: Hash> Hash for Punctuated<T, P>
impl<T: Hash, P: Hash> Hash for Punctuated<T, P>
sourceimpl<T, P> Index<usize> for Punctuated<T, P>
impl<T, P> Index<usize> for Punctuated<T, P>
sourceimpl<T, P> IndexMut<usize> for Punctuated<T, P>
impl<T, P> IndexMut<usize> for Punctuated<T, P>
sourceimpl<T, P> IntoIterator for Punctuated<T, P>
impl<T, P> IntoIterator for Punctuated<T, P>
sourceimpl<'a, T, P> IntoIterator for &'a Punctuated<T, P>
impl<'a, T, P> IntoIterator for &'a Punctuated<T, P>
sourceimpl<'a, T, P> IntoIterator for &'a mut Punctuated<T, P>
impl<'a, T, P> IntoIterator for &'a mut Punctuated<T, P>
sourceimpl<T, P> Parse for Punctuated<T, P> where
T: Parse,
P: Parse,
impl<T, P> Parse for Punctuated<T, P> where
T: Parse,
P: Parse,
fn parse(input: ParseStream<'_>) -> Result<Self>
sourceimpl<T: PartialEq, P: PartialEq> PartialEq<Punctuated<T, P>> for Punctuated<T, P>
impl<T: PartialEq, P: PartialEq> PartialEq<Punctuated<T, P>> for Punctuated<T, P>
sourcefn eq(&self, other: &Punctuated<T, P>) -> bool
fn eq(&self, other: &Punctuated<T, P>) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &Punctuated<T, P>) -> bool
fn ne(&self, other: &Punctuated<T, P>) -> bool
This method tests for !=
.
sourceimpl<T, P> ToTokens for Punctuated<T, P> where
T: ToTokens,
P: ToTokens,
impl<T, P> ToTokens for Punctuated<T, P> where
T: ToTokens,
P: ToTokens,
sourcefn to_tokens(&self, tokens: &mut TokenStream)
fn to_tokens(&self, tokens: &mut TokenStream)
Write self
to the given TokenStream
. Read more
sourcefn to_token_stream(&self) -> TokenStream
fn to_token_stream(&self) -> TokenStream
Convert self
directly into a TokenStream
object. Read more
sourcefn into_token_stream(self) -> TokenStream
fn into_token_stream(self) -> TokenStream
Convert self
directly into a TokenStream
object. Read more
impl<T: Eq, P: Eq> Eq for Punctuated<T, P>
impl<T, P> StructuralEq for Punctuated<T, P>
impl<T, P> StructuralPartialEq for Punctuated<T, P>
Auto Trait Implementations
impl<T, P> RefUnwindSafe for Punctuated<T, P> where
P: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, P> Send for Punctuated<T, P> where
P: Send,
T: Send,
impl<T, P> Sync for Punctuated<T, P> where
P: Sync,
T: Sync,
impl<T, P> Unpin for Punctuated<T, P> where
P: Unpin,
T: Unpin,
impl<T, P> UnwindSafe for Punctuated<T, P> where
P: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> FormatSpan for T where
T: Spanned + ?Sized,
impl<T> FormatSpan for T where
T: Spanned + ?Sized,
fn format_span(&self) -> SpanDisplay
sourceimpl<T> Spanned for T where
T: Spanned + ?Sized,
impl<T> Spanned for T where
T: Spanned + ?Sized,
sourcefn span(&self) -> Span
fn span(&self) -> Span
Returns a Span
covering the complete contents of this syntax tree
node, or Span::call_site()
if this node is empty. Read more