Module syn::punctuated

source ·
Expand description

A punctuated sequence of syntax tree nodes separated by punctuation.

Lots of things in Rust are punctuated sequences.

  • The fields of a struct are Punctuated<Field, Token![,]>.
  • The segments of a path are Punctuated<PathSegment, Token![::]>.
  • The bounds on a generic parameter are Punctuated<TypeParamBound, Token![+]>.
  • The arguments to a function call are Punctuated<Expr, Token![,]>.

This module provides a common representation for these punctuated sequences in the form of the Punctuated<T, P> type. We store a vector of pairs of syntax tree node + punctuation, where every node in the sequence is followed by punctuation except for possibly the final one.

a_function_call(arg1, arg2, arg3);
                ~~~~^ ~~~~^ ~~~~

Structs§

  • An iterator over owned values of type T.
  • An iterator over owned pairs of type Pair<T, P>.
  • An iterator over borrowed values of type &T.
  • An iterator over mutably borrowed values of type &mut T.
  • An iterator over borrowed pairs of type Pair<&T, &P>.
  • An iterator over mutably borrowed pairs of type Pair<&mut T, &mut P>.
  • A punctuated sequence of syntax tree nodes of type T separated by punctuation of type P.

Enums§

  • A single syntax tree node of type T followed by its trailing punctuation of type P if any.