Struct Punctuated

Source
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    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    }
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 duplicate 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>

Source§

type Item = T

The type of the elements being iterated over.
Source§

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> Freeze for Punctuated<T, P>
where T: Freeze,

§

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

§

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

§

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

§

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

§

impl<T, P> UnwindSafe for Punctuated<T, P>
where T: UnwindSafe, P: 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> 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<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 = 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>,

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.