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);
let values: Pluses = m2_syn::punc!(
pairs m2_syn::Token);
comma => m2_syn::Token),
);
assert_eq!(values.to_m2(), "+,+");Implementations§
Source§impl<S, P> Punctuated<S, P>
impl<S, P> Punctuated<S, P>
Sourcepub fn new(first: S, punctuation: P, second: S) -> Self
pub fn new(first: S, punctuation: P, second: S) -> Self
Creates a sequence from the first two values and their punctuation.
Sourcepub fn from_pair(pair: SeparatedPair<S, P>) -> Self
pub fn from_pair(pair: SeparatedPair<S, P>) -> Self
Creates a two-value sequence from one punctuated pair.
Sourcepub fn from_pair_and_rest(pair: SeparatedPair<S, P>, rest: Vec<(P, S)>) -> Self
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.
Sourcepub fn pairs(&self) -> Pairs<'_, S, P>
pub fn pairs(&self) -> Pairs<'_, S, P>
Borrows every punctuation-value pair following the first value.
Sourcepub fn pairs_mut(&mut self) -> PairsMut<'_, S, P>
pub fn pairs_mut(&mut self) -> PairsMut<'_, S, P>
Mutably borrows every punctuation-value pair following the first value.
Sourcepub fn into_parts(self) -> (SeparatedPair<S, P>, Vec<(P, S)>)
pub fn into_parts(self) -> (SeparatedPair<S, P>, Vec<(P, S)>)
Separates the sequence into its first pair and any later pairs.
Sourcepub const fn is_empty(&self) -> bool
pub const fn is_empty(&self) -> bool
Returns false; a punctuated sequence always contains at least two values.
Sourcepub fn iter(&self) -> Values<'_, S, P>
pub fn iter(&self) -> Values<'_, S, P>
Borrows the values without discarding or synthesizing punctuation.
Sourcepub fn iter_mut(&mut self) -> ValuesMut<'_, S, P>
pub fn iter_mut(&mut self) -> ValuesMut<'_, S, P>
Mutably borrows the values without discarding or synthesizing punctuation.
Sourcepub fn push(&mut self, punctuation: P, value: S)
pub fn push(&mut self, punctuation: P, value: S)
Appends a real punctuation token and the value following it.
Sourcepub fn map_values<T>(self, map: impl FnMut(S) -> T) -> Punctuated<T, P>
pub fn map_values<T>(self, map: impl FnMut(S) -> T) -> Punctuated<T, P>
Maps the values while retaining every punctuation token unchanged.
Trait Implementations§
Source§impl<S: Clone, P: Clone> Clone for Punctuated<S, P>
impl<S: Clone, P: Clone> Clone for Punctuated<S, P>
Source§fn clone(&self) -> Punctuated<S, P>
fn clone(&self) -> Punctuated<S, P>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl<S: Eq, P: Eq> Eq for Punctuated<S, P>
Source§impl<S, P> IntoIterator for Punctuated<S, P>
impl<S, P> IntoIterator for Punctuated<S, P>
Source§impl<'a, S, P> IntoIterator for &'a Punctuated<S, P>
impl<'a, S, P> IntoIterator for &'a Punctuated<S, P>
Source§impl<'a, S, P> IntoIterator for &'a mut Punctuated<S, P>
impl<'a, S, P> IntoIterator for &'a mut Punctuated<S, P>
Source§impl<S: Lex, P: Lex> Lex for Punctuated<S, P>
impl<S: Lex, P: Lex> Lex for Punctuated<S, P>
Source§fn to_tokens(&self, output: &mut TokenStream)
fn to_tokens(&self, output: &mut TokenStream)
output.Source§fn to_token_stream(&self) -> TokenStream
fn to_token_stream(&self) -> TokenStream
Source§impl<S, P> Parse for Punctuated<S, P>
impl<S, P> Parse for Punctuated<S, P>
Source§fn parse(input: &mut ParseStream) -> Result<Self, TokenParseError>
fn parse(input: &mut ParseStream) -> Result<Self, TokenParseError>
input. Read more