Skip to main content

Punctuated

Struct Punctuated 

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

A nonempty sequence of syntax values separated by typed punctuation.

Every separator is stored as its actual token, including its source span. The first value is mandatory; optional or empty grammar positions belong in the element type, such as Option<T> or a syntax enum containing an empty variant, 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::detached());
let values: Pluses = m2_syn::punc!(
    pairs m2_syn::Token![+](Span::detached());
    comma => m2_syn::Token![+](Span::detached()),
);
assert_eq!(values.to_m2(), "+,+");

Implementations§

Source§

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

Source

pub fn new(first: S, rest: Vec<(P, S)>) -> Self

Creates a sequence from its first value and remaining punctuation-value pairs.

Source

pub fn from_single(value: S) -> Self

Creates a sequence containing exactly one value.

Source

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

Creates a two-value sequence from one punctuated pair.

Source

pub fn first(&self) -> &S

Returns the first value.

Examples found in repository?
examples/type_inference.rs (line 287)
285fn infer(source: &str, context: &DemoRegistry) -> Result<DemoFact, ParseError> {
286    let file = parse_file(source)?;
287    let expression = match file.cells[0].content.pack.first() {
288        Component::Expr(expression) => expression.as_ref(),
289        Component::Empty(_) => panic!("expected an expression component"),
290    };
291    Ok(TypeChecker {
292        context,
293        results: Vec::new(),
294    }
295    .infer(expression))
296}
Source

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

Returns the first value mutably.

Source

pub fn rest(&self) -> &[(P, S)]

Returns the punctuation-value pairs following the first value.

Source

pub fn rest_mut(&mut self) -> &mut [(P, S)]

Returns the punctuation-value pairs following the first value mutably.

Source

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

Separates the sequence into its first value and remaining 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 its first value.

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.

Examples found in repository?
examples/type_inference.rs (line 72)
69    fn components(&mut self, components: &Option<ExprPack>) -> Vec<FactOf<C>> {
70        components
71            .iter()
72            .flat_map(|pack| pack.pack.iter())
73            .filter_map(|component| match component {
74                Component::Expr(expression) => Some(self.infer(expression)),
75                Component::Empty(_) => None,
76            })
77            .collect()
78    }
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.

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<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<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<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>
where S: Spanned, Vec<(P, S)>: Spanned,

Source§

fn span(&self) -> Span

Returns the smallest span covering this value.
Source§

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

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

impl<S, P> Unpin for Punctuated<S, P>
where 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, <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.