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);
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, rest: Vec<(P, S)>) -> Self
pub fn new(first: S, rest: Vec<(P, S)>) -> Self
Creates a sequence from its first value and remaining punctuation-value pairs.
Sourcepub fn from_single(value: S) -> Self
pub fn from_single(value: S) -> Self
Creates a sequence containing exactly one value.
Sourcepub fn from_pair(pair: PunctPair<S, P>) -> Self
pub fn from_pair(pair: PunctPair<S, P>) -> Self
Creates a two-value sequence from one punctuated pair.
Sourcepub fn first(&self) -> &S
pub fn first(&self) -> &S
Returns the first value.
Examples found in repository?
286fn infer(source: &str, context: &DemoRegistry) -> Result<DemoFact, ParseError> {
287 let file = parse_file(source)?;
288 let expression = match file.cells[0].content.pack.first() {
289 Component::Expr(expression) => expression.as_ref(),
290 Component::Empty(_) => panic!("expected an expression component"),
291 };
292 Ok(TypeChecker {
293 context,
294 results: Vec::new(),
295 }
296 .infer(expression))
297}Sourcepub fn rest_mut(&mut self) -> &mut [(P, S)]
pub fn rest_mut(&mut self) -> &mut [(P, S)]
Returns the punctuation-value pairs following the first value mutably.
Sourcepub fn into_parts(self) -> (S, Vec<(P, S)>)
pub fn into_parts(self) -> (S, Vec<(P, S)>)
Separates the sequence into its first value and remaining pairs.
Sourcepub const fn is_empty(&self) -> bool
pub const fn is_empty(&self) -> bool
Returns false; a punctuated sequence always contains its first value.
Sourcepub fn iter(&self) -> Values<'_, S, P>
pub fn iter(&self) -> Values<'_, S, P>
Borrows the values without discarding or synthesizing punctuation.
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