pub struct Punctuated<T, P: Punct> { /* private fields */ }
Expand description
A series of pairs of T
and P
, optionally followed by another T
.
Implementations§
Source§impl<T, P: Punct> Punctuated<T, P>
impl<T, P: Punct> Punctuated<T, P>
Sourcepub fn parse_separated(input: ParseStream<'_>) -> Result<Self>where
T: Parse,
pub fn parse_separated(input: ParseStream<'_>) -> Result<Self>where
T: Parse,
Parses instances of T
separated by instances of P
, with no trailing
punctuation.
Note that this will stop as soon as it encounters a token that doesn’t fit this pattern.
§Errors
Forwards any errors from T::parse
.
Sourcepub fn parse_separated_with<F: FnMut(ParseStream<'_>) -> Result<T>>(
input: ParseStream<'_>,
f: F,
) -> Result<Self>
pub fn parse_separated_with<F: FnMut(ParseStream<'_>) -> Result<T>>( input: ParseStream<'_>, f: F, ) -> Result<Self>
Parses instances of T
using f
, separated by instances of P
, with
no trailing punctuation.
Note that this will stop as soon as it encounters a token that doesn’t fit this pattern.
§Errors
Forwards any errors from f
.
Sourcepub fn parse_separated_trailing(input: ParseStream<'_>) -> Result<Self>where
T: Parse,
pub fn parse_separated_trailing(input: ParseStream<'_>) -> Result<Self>where
T: Parse,
Parses instances of T
separated by instances of P
, with optional
trailing punctuation.
Note that this will stop as soon as it encounters a token that doesn’t fit this pattern.
§Errors
Forwards any errors from T::parse
.
Examples found in repository?
358 fn finish_call(input: ParseStream<'_>, callee: Expr) -> Result<Self> {
359 let content;
360 let paren: Parentheses = group!(content in input);
361 let arguments: Punctuated<Expr, Punct![","]> =
362 Punctuated::parse_separated_trailing(&content)?;
363 let arguments: Vec<_> = arguments.into_iter().collect();
364 if arguments.len() >= 255 {
365 input.add_error(input.new_error(
366 "Can't have more than 254 arguments".to_string(),
367 paren.0.clone(),
368 error_codes::TOO_MANY_ARGS,
369 ));
370 }
371 Ok(Expr::Call {
372 callee: Box::new(callee),
373 paren,
374 arguments,
375 })
376 }
Sourcepub fn parse_separated_trailing_with<F: FnMut(ParseStream<'_>) -> Result<T>>(
input: ParseStream<'_>,
f: F,
) -> Result<Self>
pub fn parse_separated_trailing_with<F: FnMut(ParseStream<'_>) -> Result<T>>( input: ParseStream<'_>, f: F, ) -> Result<Self>
Parses instances of T
using f
, separated by instances of P
, with
optional trailing punctuation.
Note that this will stop as soon as it encounters a token that doesn’t fit this pattern.
§Errors
Forwards any errors from f
.
Sourcepub fn parse_terminated(input: ParseStream<'_>) -> Result<Self>where
T: Parse,
pub fn parse_terminated(input: ParseStream<'_>) -> Result<Self>where
T: Parse,
Parses instances of T
separated by instances of P
, with trailing
punctuation.
Note that this function attempts to consume the entire stream.
§Errors
Forwards any errors from T::parse
.
Sourcepub fn parse_terminated_with<F: FnMut(ParseStream<'_>) -> Result<T>>(
input: ParseStream<'_>,
f: F,
) -> Result<Self>
pub fn parse_terminated_with<F: FnMut(ParseStream<'_>) -> Result<T>>( input: ParseStream<'_>, f: F, ) -> Result<Self>
trailing punctuation.
Note that this function attempts to consume the entire stream.
§Errors
Forwards any errors from f
.
Sourcepub fn iter_mut(&mut self) -> IterMut<'_, T, P> ⓘ
pub fn iter_mut(&mut self) -> IterMut<'_, T, P> ⓘ
Returns an iterator that allows modifying each value.
Sourcepub fn pairs(&self) -> Pairs<'_, T, P> ⓘ
pub fn pairs(&self) -> Pairs<'_, T, P> ⓘ
Returns an iterator over the pairs of values and punctuation in this struct.
Sourcepub fn pairs_mut(&mut self) -> PairsMut<'_, T, P> ⓘ
pub fn pairs_mut(&mut self) -> PairsMut<'_, T, P> ⓘ
Returns an iterator that allows modifying each pair.
Sourcepub fn into_pairs(self) -> IntoPairs<T, P> ⓘ
pub fn into_pairs(self) -> IntoPairs<T, P> ⓘ
Returns a consuming iterator over the pairs in this struct.
Trait Implementations§
Source§impl<T: Clone, P: Clone + Punct> Clone for Punctuated<T, P>
impl<T: Clone, P: Clone + Punct> Clone for Punctuated<T, P>
Source§fn clone(&self) -> Punctuated<T, P>
fn clone(&self) -> Punctuated<T, P>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more