pub struct Punctuated<T> { /* private fields */ }
Expand description

A punctuated sequence of node T separated by TokenReference. Refer to the module documentation for more details.

Implementations§

source§

impl<T> Punctuated<T>

source

pub fn new() -> Self

Creates an empty punctuated sequence

let mut punctuated: Punctuated<i32> = Punctuated::new();
source

pub fn is_empty(&self) -> bool

Returns whether there’s any nodes in the punctuated sequence

let mut punctuated = Punctuated::new();
assert!(punctuated.is_empty());
punctuated.push(Pair::new((), None));
assert!(!punctuated.is_empty());
source

pub fn len(&self) -> usize

Returns the number of pairs in the punctuated sequence

let mut punctuated = Punctuated::new();
assert_eq!(punctuated.len(), 0);
punctuated.push(Pair::new((), None));
assert_eq!(punctuated.len(), 1);
source

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

Returns an iterator over references of the sequence values, ignoring punctuation

let mut punctuated = Punctuated::new();
punctuated.push(Pair::new(1, None));
let mut iterator = punctuated.iter();
assert_eq!(iterator.next(), Some(&1));
assert_eq!(iterator.next(), None);
source

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

Returns an iterator over mutable references of the sequence values, ignoring punctuation

let mut punctuated = Punctuated::new();
punctuated.push(Pair::new(1, None));
for item in punctuated.iter_mut() {
    *item += 1;
}
assert_eq!(punctuated.pop(), Some(Pair::new(2, None)));
source

pub fn into_pairs(self) -> impl Iterator<Item = Pair<T>>

Returns an iterator over pairs

let mut punctuated = Punctuated::new();
punctuated.push(Pair::new(1, None));
let mut iterator = punctuated.into_pairs();
assert_eq!(iterator.next(), Some(Pair::new(1, None)));
assert_eq!(iterator.next(), None);
source

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

Returns the first pair in the sequence

let mut punctuated = Punctuated::new();
assert_eq!(punctuated.first(), None);
punctuated.push(Pair::new(1, None));
assert_eq!(punctuated.first(), Some(&Pair::new(1, None)));
source

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

Returns the last pair in the sequence

let mut punctuated = Punctuated::new();
punctuated.push(Pair::new(1, None));
assert_eq!(punctuated.last(), Some(&Pair::new(1, None)));
source

pub fn pairs(&self) -> impl Iterator<Item = &Pair<T>>

Returns an iterator over pairs as references

let mut punctuated = Punctuated::new();
punctuated.push(Pair::new(1, None));
let mut iterator = punctuated.pairs();
assert_eq!(iterator.next(), Some(&Pair::new(1, None)));
assert_eq!(iterator.next(), None);
source

pub fn pairs_mut(&mut self) -> impl Iterator<Item = &mut Pair<T>>

Returns an iterator over pairs as mutable references

let mut punctuated = Punctuated::new();
punctuated.push(Pair::new(1, None));
for item in punctuated.pairs_mut() {
    *item.value_mut() += 1;
}
assert_eq!(punctuated.pop(), Some(Pair::new(2, None)));
source

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

Pops off the last pair if it isn’t empty

let mut punctuated = Punctuated::new();
punctuated.push(Pair::new(1, None));
assert_eq!(punctuated.pop(), Some(Pair::new(1, None)));
source

pub fn push(&mut self, pair: Pair<T>)

Pushes a new pair onto the sequence

let mut punctuated = Punctuated::new();
punctuated.push(Pair::new(1, None));
assert_eq!(punctuated.pop(), Some(Pair::new(1, None)));

Trait Implementations§

source§

impl<T: Clone> Clone for Punctuated<T>

source§

fn clone(&self) -> Punctuated<T>

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl<T: Debug> Debug for Punctuated<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T: Default> Default for Punctuated<T>

source§

fn default() -> Punctuated<T>

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

impl<'de, T> Deserialize<'de> for Punctuated<T>where T: Deserialize<'de>,

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<T> Display for Punctuated<T>where T: Display,

source§

fn fmt(&self, _derive_more_display_formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T> Extend<Pair<T>> for Punctuated<T>

source§

fn extend<I: IntoIterator<Item = Pair<T>>>(&mut self, iter: 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> FromIterator<Pair<T>> for Punctuated<T>

source§

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

Creates a value from an iterator. Read more
source§

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

§

type Item = &'a T

The type of the elements being iterated over.
§

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> IntoIterator for &'a mut Punctuated<T>

§

type Item = &'a mut T

The type of the elements being iterated over.
§

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> IntoIterator for Punctuated<T>

§

type Item = T

The type of the elements being iterated over.
§

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: Node> Node for Punctuated<T>

source§

fn start_position(&self) -> Option<Position>

The start position of a node. None if can’t be determined
source§

fn end_position(&self) -> Option<Position>

The end position of a node. None if it can’t be determined
source§

fn similar(&self, other: &Self) -> bool

Whether another node of the same type is the same as this one semantically, ignoring position
source§

fn tokens(&self) -> Tokens<'_>

The token references that comprise a node
source§

fn range(&self) -> Option<(Position, Position)>

The full range of a node, if it has both start and end positions
source§

fn surrounding_trivia(&self) -> (Vec<&Token>, Vec<&Token>)

The tokens surrounding a node that are ignored and not accessible through the node’s own accessors. Use this if you want to get surrounding comments or whitespace. Returns a tuple of the leading and trailing trivia.
source§

impl<T: PartialEq> PartialEq for Punctuated<T>

source§

fn eq(&self, other: &Punctuated<T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T> Serialize for Punctuated<T>where T: Serialize,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<T: Eq> Eq for Punctuated<T>

source§

impl<T> StructuralEq for Punctuated<T>

source§

impl<T> StructuralPartialEq for Punctuated<T>

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for Punctuated<T>where T: RefUnwindSafe,

§

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

§

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

§

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

§

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

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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> ToOwned for Twhere T: Clone,

§

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> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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 Twhere U: TryFrom<T>,

§

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

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,