syn::punctuated

Struct 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>

Source

pub const fn new() -> Self

Creates an empty punctuated sequence.

Source

pub fn is_empty(&self) -> bool

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

Source

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.

Source

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

Borrows the first element in this sequence.

Source

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

Mutably borrows the first element in this sequence.

Source

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

Borrows the last element in this sequence.

Source

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

Mutably borrows the last element in this sequence.

Source

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

Borrows the element at the given index.

Source

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

Mutably borrows the element at the given index.

Source

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

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

Source

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

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

Source

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

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

Source

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

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

Source

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

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

Source

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.

Source

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.

Source

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

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

Source

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

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

Source

pub fn trailing_punct(&self) -> bool

Determines whether this punctuated sequence ends with a trailing punctuation.

Source

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

Source

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.

Source

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.

Source

pub fn clear(&mut self)

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

Source

pub 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.

Source

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.

Source

pub 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.

Source

pub fn parse_separated_nonempty_with( input: ParseStream<'_>, parser: fn(_: ParseStream<'_>) -> 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§

Source§

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

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
Source§

fn clone_from(&mut self, other: &Self)

Performs copy-assignment from source. Read more
Source§

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

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

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)

Extends a collection with the contents of an iterator. Read more
Source§

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)

🔬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<T, P> Extend<T> for Punctuated<T, P>
where P: Default,

Source§

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

Extends a collection with the contents of an iterator. Read more
Source§

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)

🔬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<T, P> FromIterator<Pair<T, P>> for Punctuated<T, P>

Source§

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

Creates a value from an iterator. Read more
Source§

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

Source§

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

Creates a value from an iterator. Read more
Source§

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

Source§

type Output = T

The returned type after indexing.
Source§

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

Performs the indexing (container[index]) operation. Read more
Source§

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

Source§

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

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<'a, T, P> IntoIterator for &'a Punctuated<T, P>

Source§

type Item = &'a T

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, T, P> IntoIterator for &'a mut Punctuated<T, P>

Source§

type Item = &'a mut T

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'a, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

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

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

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

Source§

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

Write self to the given TokenStream. Read more
Source§

fn to_token_stream(&self) -> TokenStream

Convert self directly into a TokenStream object. Read more
Source§

fn into_token_stream(self) -> TokenStream
where Self: Sized,

Convert self directly into a TokenStream object. Read more

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

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

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

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

Source§

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.
Source§

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

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

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

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.