Skip to main content

Punctuated

Struct Punctuated 

Source
pub struct Punctuated<S, P = _Cma> { /* private fields */ }
Expand description

Two or more syntax values separated by typed punctuation.

Every separator is stored as its actual token, including its source span. At least one separator and the values on both sides are mandatory. A single value belongs directly in the surrounding syntax type, while an optional whole sequence is Option<Punctuated<T, P>>.

use m2_syn::{Lex, Span};

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

Implementations§

Source§

impl<S, P> Punctuated<S, P>

Source

pub fn new(first: S, punctuation: P, second: S) -> Self

Creates a sequence from the first two values and their punctuation.

Source

pub fn from_pair(pair: SeparatedPair<S, P>) -> Self

Creates a two-value sequence from one punctuated pair.

Source

pub fn from_pair_and_rest(pair: SeparatedPair<S, P>, rest: Vec<(P, S)>) -> Self

Creates a sequence from its first separated pair and any later punctuation-value pairs.

Source

pub fn first(&self) -> &S

Returns the first value.

Source

pub fn first_mut(&mut self) -> &mut S

Returns the first value mutably.

Source

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

Borrows every punctuation-value pair following the first value.

Source

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

Mutably borrows every punctuation-value pair following the first value.

Source

pub fn into_parts(self) -> (SeparatedPair<S, P>, Vec<(P, S)>)

Separates the sequence into its first pair and any later pairs.

Source

pub fn len(&self) -> usize

Returns the number of values, excluding punctuation.

Source

pub const fn is_empty(&self) -> bool

Returns false; a punctuated sequence always contains at least two values.

Source

pub fn token_len(&self) -> usize

Returns the number of values and punctuation tokens together.

Source

pub fn iter(&self) -> Values<'_, S, P>

Borrows the values without discarding or synthesizing punctuation.

Source

pub fn iter_mut(&mut self) -> ValuesMut<'_, S, P>

Mutably borrows the values without discarding or synthesizing punctuation.

Source

pub fn push(&mut self, punctuation: P, value: S)

Appends a real punctuation token and the value following it.

Source

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

Maps the values while retaining every punctuation token unchanged.

Source

pub fn try_map<T, Q, E>( self, map_value: impl FnMut(S) -> Result<T, E>, map_punct: impl FnMut(P) -> Result<Q, E>, ) -> Result<Punctuated<T, Q>, E>

Fallibly maps both values and punctuation while retaining their order.

§Errors

Returns the first error produced by either mapping function.

Trait Implementations§

Source§

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

Source§

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

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, P: Debug> Debug for Punctuated<S, P>

Source§

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

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

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

Source§

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

Source§

type Item = S

The type of the elements being iterated over.
Source§

type IntoIter = Chain<Once<S>, Map<Chain<Once<(P, S)>, IntoIter<(P, S)>>, fn((P, S)) -> 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, P> IntoIterator for &'a Punctuated<S, P>

Source§

type Item = &'a S

The type of the elements being iterated over.
Source§

type IntoIter = Chain<Once<&'a S>, Map<Chain<Once<&'a (P, S)>, Iter<'a, (P, S)>>, fn(&(P, S)) -> &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, P> IntoIterator for &'a mut Punctuated<S, P>

Source§

type Item = &'a mut S

The type of the elements being iterated over.
Source§

type IntoIter = Chain<Once<&'a mut S>, Map<Chain<Once<&'a mut (P, S)>, IterMut<'a, (P, S)>>, fn(&mut (P, S)) -> &mut 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: Lex, P: Lex> Lex for Punctuated<S, P>

Source§

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

Appends this value’s token trees to output.
Source§

fn to_token_stream(&self) -> TokenStream

Emits this value into a fresh token stream.
Source§

fn to_m2(&self) -> String

Renders this value as normalized Macaulay2 source.
Source§

impl<S, P> Parse for Punctuated<S, P>
where S: Parse, P: Parse + Token,

Source§

fn parse(input: &mut ParseStream) -> Result<Self, TokenParseError>

Consumes this value from input. Read more
Source§

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

Source§

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

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

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

Inequality operator !=. Read more
Source§

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

Source§

fn pretty_tree(&self) -> PrettyNode

Builds the presentation node for this syntax value.
Source§

impl<S, P> Spanned for Punctuated<S, P>

Source§

fn try_span(&self) -> Option<Span>

Returns the smallest span covering this value, when its constituents share one source snapshot.
Source§

fn span(&self) -> Span

Returns the smallest span covering this value. Read more
Source§

fn expect_span(&self) -> Span

Returns this value’s span when one source snapshot covers it. Read more
Source§

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

Auto Trait Implementations§

§

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

§

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

§

impl<S, P> Send for Punctuated<S, P>
where S: Send, (P, S): Send, Vec<(P, S)>: Send,

§

impl<S, P> Sync for Punctuated<S, P>
where S: Sync, (P, S): Sync, Vec<(P, S)>: Sync,

§

impl<S, P> Unpin for Punctuated<S, P>
where S: Unpin, (P, S): Unpin, Vec<(P, S)>: Unpin,

§

impl<S, P> UnsafeUnpin for Punctuated<S, P>

§

impl<S, P> UnwindSafe for Punctuated<S, P>

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.