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>

source

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.

source

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.

source

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?
examples/lox/main.rs (line 362)
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
    fn finish_call(input: ParseStream<'_>, callee: Expr) -> Result<Self> {
        let content;
        let paren: Parentheses = group!(content in input);
        let arguments: Punctuated<Expr, Punct![","]> =
            Punctuated::parse_separated_trailing(&content)?;
        let arguments: Vec<_> = arguments.into_iter().collect();
        if arguments.len() >= 255 {
            input.add_error(input.new_error(
                "Can't have more than 254 arguments".to_string(),
                paren.0.clone(),
                error_codes::TOO_MANY_ARGS,
            ));
        }
        Ok(Expr::Call {
            callee: Box::new(callee),
            paren,
            arguments,
        })
    }
source

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.

source

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.

source

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.

source

pub fn iter(&self) -> Iter<'_, T, P>

Returns an iterator over the values in this struct.

source

pub fn iter_mut(&mut self) -> IterMut<'_, T, P>

Returns an iterator that allows modifying each value.

source

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

Returns an iterator over the pairs of values and punctuation in this struct.

source

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

Returns an iterator that allows modifying each pair.

source

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>

source§

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

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug, P: Debug + Punct> Debug for Punctuated<T, P>

source§

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

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

impl<T, P: Punct> IntoIterator for Punctuated<T, P>

§

type Item = T

The type of the elements being iterated over.
§

type IntoIter = IntoIter<T, P>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

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

§

impl<T, P> Send for Punctuated<T, P>
where P: Send, T: Send,

§

impl<T, P> Sync for Punctuated<T, P>
where P: Sync, T: Sync,

§

impl<T, P> Unpin for Punctuated<T, P>
where P: Unpin, T: Unpin,

§

impl<T, P> UnwindSafe for Punctuated<T, P>
where P: UnwindSafe, T: UnwindSafe,

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> 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<T> ToOwned for T
where T: Clone,

§

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>,

§

type Error = Infallible

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>,

§

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.