Struct Punctuated

pub struct Punctuated<T, P> { /* private fields */ }

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

impl<T, P> Punctuated<T, P>

const fn new() -> Self

Creates an empty punctuated sequence.

fn is_empty(&self) -> bool

Determines whether this punctuated sequence is empty, meaning it contains no syntax tree nodes or punctuation.

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.

fn first(&self) -> Option<&T>

Borrows the first element in this sequence.

fn first_mut(&mut self) -> Option<&mut T>

Mutably borrows the first element in this sequence.

fn last(&self) -> Option<&T>

Borrows the last element in this sequence.

fn last_mut(&mut self) -> Option<&mut T>

Mutably borrows the last element in this sequence.

fn get(&self, index: usize) -> Option<&T>

Borrows the element at the given index.

fn get_mut(&mut self, index: usize) -> Option<&mut T>

Mutably borrows the element at the given index.

fn iter(&self) -> Iter<'_, T>

Returns an iterator over borrowed syntax tree nodes of type &T.

fn iter_mut(&mut self) -> IterMut<'_, T>

Returns an iterator over mutably borrowed syntax tree nodes of type &mut T.

fn pairs(&self) -> Pairs<'_, T, P>

Returns an iterator over the contents of this sequence as borrowed punctuated pairs.

fn pairs_mut(&mut self) -> PairsMut<'_, T, P>

Returns an iterator over the contents of this sequence as mutably borrowed punctuated pairs.

fn into_pairs(self) -> IntoPairs<T, P>

Returns an iterator over the contents of this sequence as owned punctuated pairs.

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.

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.

fn pop(&mut self) -> Option<T>

Removes the last element from this sequence, discarding the trailing punctuation if any.

fn pop_punct(&mut self) -> Option<P>

Removes the trailing punctuation from this punctuated sequence, or None if there isn't any.

fn pop_pair(&mut self) -> Option<Pair<T, P>>

Removes the last punctuated pair from this sequence, or None if the sequence is empty.

fn trailing_punct(&self) -> bool

Determines whether this punctuated sequence ends with a trailing punctuation.

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().

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.

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.

fn clear(&mut self)

Clears the sequence of all values and punctuation, making it empty.

fn parse_terminated(input: ParseStream<'_>) -> Result<Self>
where
    T: Parse,
    P: Parse,

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.

fn parse_terminated_with<'a>(input: ParseStream<'a>, parser: fn(ParseStream<'a>) -> 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.

fn parse_separated_nonempty(input: ParseStream<'_>) -> Result<Self>
where
    T: Parse,
    P: Token + Parse,

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.

fn parse_separated_nonempty_with<'a>(input: ParseStream<'a>, parser: fn(ParseStream<'a>) -> Result<T>) -> Result<Self>
where
    P: Token + Parse,

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

impl<T, P> Clone for Punctuated<T, P> where T: Clone, P: Clone,

fn clone(&self) -> Self
fn clone_from(&mut self, other: &Self)

impl<T, P> Default for Punctuated<T, P>

fn default() -> Self

impl<T, P> Extend<Pair<T, P>> for Punctuated<T, P> where P: Default,

fn extend<I: IntoIterator<Item = Pair<T, P>>>(&mut self, i: I)

impl<T, P> Extend<T> for Punctuated<T, P> where P: Default,

fn extend<I: IntoIterator<Item = T>>(&mut self, i: I)

impl<T, P> FromIterator<Pair<T, P>> for Punctuated<T, P>

fn from_iter<I: IntoIterator<Item = Pair<T, P>>>(i: I) -> Self

impl<T, P> FromIterator<T> for Punctuated<T, P> where P: Default,

fn from_iter<I: IntoIterator<Item = T>>(i: I) -> Self

impl<T, P> Index<usize> for Punctuated<T, P>

type Output = T;
fn index(&self, index: usize) -> &Self::Output

impl<T, P> IndexMut<usize> for Punctuated<T, P>

fn index_mut(&mut self, index: usize) -> &mut Self::Output

impl<T, P> IntoIterator for Punctuated<T, P>

type Item = T;
type IntoIter = IntoIter<T>;
fn into_iter(self) -> Self::IntoIter

impl<T, P> ToTokens for Punctuated<T, P> where T: ToTokens, P: ToTokens,

fn to_tokens(&self, tokens: &mut TokenStream)

Auto Trait Implementations

impl<T, P> Freeze for Punctuated<T, P> where Vec<(T, P)>: Freeze, Option<Box<T>>: Freeze,

impl<T, P> RefUnwindSafe for Punctuated<T, P> where Vec<(T, P)>: RefUnwindSafe, Option<Box<T>>: RefUnwindSafe,

impl<T, P> Send for Punctuated<T, P> where Vec<(T, P)>: Send, Option<Box<T>>: Send,

impl<T, P> Sync for Punctuated<T, P> where Vec<(T, P)>: Sync, Option<Box<T>>: Sync,

impl<T, P> Unpin for Punctuated<T, P> where Vec<(T, P)>: Unpin, Option<Box<T>>: Unpin,

impl<T, P> UnsafeUnpin for Punctuated<T, P> where Vec<(T, P)>: UnsafeUnpin, Option<Box<T>>: UnsafeUnpin,

impl<T, P> UnwindSafe for Punctuated<T, P> where Vec<(T, P)>: UnwindSafe, Option<Box<T>>: UnwindSafe,

Blanket Implementations

impl<T> Any for Punctuated<T, P> where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for Punctuated<T, P> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for Punctuated<T, P> where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> CloneToUninit for Punctuated<T, P> where T: Clone,

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for Punctuated<T, P>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> Spanned for Punctuated<T, P> where T: Spanned + ?Sized,

fn span(&self) -> Span

impl<T> ToOwned for Punctuated<T, P> where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T, U> Into<U> for Punctuated<T, P> where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for Punctuated<T, P> where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

impl<T, U> TryInto<U> for Punctuated<T, P> where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>