Skip to main content

Punctuated

Struct Punctuated 

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

A sequence of syntax values separated by typed comma tokens.

Ordinary iteration exposes only values. Use Punctuated::pairs or Punctuated::into_pairs when punctuation and its spans are significant.

use m2_syn::{Span, ToTokens};

type Pluses = m2_syn::punct!(m2_syn::Token![+]);
let comma = m2_syn::Token![,](Span::detached());
let values: Pluses = m2_syn::punct!(
    pairs m2_syn::Token![+](Span::detached());
    comma => m2_syn::Token![+](Span::detached()),
);
assert_eq!(values.to_m2(), "+,+");

Implementations§

Source§

impl<S> Punctuated<S>

Source

pub const fn new() -> Self

Creates an empty sequence.

Source

pub fn len(&self) -> usize

Returns the number of values, excluding punctuation.

Source

pub fn is_empty(&self) -> bool

Reports whether the sequence contains no values or punctuation.

Source

pub fn from_value(value: S) -> Self

Creates a sequence containing one value.

Source

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

Borrows the values without exposing punctuation.

Examples found in repository?
examples/type_inference.rs (line 76)
74    fn components(&mut self, components: &Punctuated<Component>) -> Vec<FactOf<C>> {
75        components
76            .iter()
77            .filter_map(|component| match component {
78                Component::Expr(expression) => Some(self.infer(expression)),
79                Component::EmptyComponent(_) => None,
80            })
81            .collect()
82    }
Source

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

Mutably borrows the values without exposing punctuation.

Source

pub fn pairs(&self) -> Pairs<'_, S> ⓘ

Borrows values together with their optional following commas.

Source

pub fn pairs_mut(&mut self) -> PairsMut<'_, S> ⓘ

Mutably borrows values together with their optional following commas.

Source

pub fn into_pairs(self) -> IntoPairs<S> ⓘ

Consumes the sequence while preserving commas in the yielded pairs.

Source

pub fn push(&mut self, punctuation: _Cma, next: S)

Adds a comma and the component on its right.

Panics if the sequence is empty. Empty components must be represented explicitly by converting Empty into S before calling this method.

Source

pub fn map<T>(self, map: impl FnMut(S) -> T) -> Punctuated<T>

Transforms the values while retaining every comma token and its span.

Trait Implementations§

Source§

impl<S: Clone> Clone for Punctuated<S>

Source§

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

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<S: Debug> Debug for Punctuated<S>

Source§

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

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

impl<S> Default for Punctuated<S>

Source§

fn default() -> Self

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

impl<S: Eq> Eq for Punctuated<S>

Source§

impl<S> FromIterator<S> for Punctuated<S>

Source§

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

Creates a value from an iterator. Read more
Source§

impl<S> IntoIterator for Punctuated<S>

Source§

type Item = S

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<S>

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, S> IntoIterator for &'a Punctuated<S>

Source§

type Item = &'a S

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, S>

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

Source§

type Item = &'a mut S

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'a, S>

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<S> Parse for Punctuated<S>
where S: Parse + From<Empty>,

Source§

impl<S: PartialEq> PartialEq for Punctuated<S>

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<T: PrettyTree + Spanned> PrettyTree for Punctuated<T>

Source§

fn pretty_tree(&self) -> PrettyNode

Builds the presentation node for this syntax value.
Source§

impl<S> Spanned for Punctuated<S>
where Vec<(S, _Cma)>: Spanned, Option<Box<S>>: Spanned,

Source§

fn span(&self) -> Span

Source§

impl<S: PartialEq> StructuralPartialEq for Punctuated<S>

Source§

impl<S: ToTokens> ToTokens for Punctuated<S>

Auto Trait Implementations§

§

impl<S> Freeze for Punctuated<S>

§

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

§

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

§

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

§

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

§

impl<S> UnsafeUnpin for Punctuated<S>

§

impl<S> UnwindSafe for Punctuated<S>
where S: 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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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<I> IntoStreamingIterator for I
where I: IntoIterator,

Source§

fn into_streaming_iter(self) -> Convert<Self::IntoIter>

Source§

fn into_streaming_iter_ref<'a, T>(self) -> ConvertRef<'a, Self::IntoIter, T>
where Self: IntoIterator<Item = &'a T>, T: ?Sized,

Turns an IntoIterator of references into a StreamingIterator. Read more
Source§

fn into_streaming_iter_mut<'a, T>(self) -> ConvertMut<'a, Self::IntoIter, T>
where Self: IntoIterator<Item = &'a mut T>, T: ?Sized,

Turns an IntoIterator of mutable references into a StreamingIteratorMut. Read more
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.