pub enum PatKind {
Show 17 variants
Wild,
Ident(BindingAnnotation, Ident, Option<P<Pat>>),
Struct(Option<P<QSelf>>, Path, ThinVec<PatField>, PatFieldsRest),
TupleStruct(Option<P<QSelf>>, Path, ThinVec<P<Pat>>),
Or(ThinVec<P<Pat>>),
Path(Option<P<QSelf>>, Path),
Tuple(ThinVec<P<Pat>>),
Box(P<Pat>),
Ref(P<Pat>, Mutability),
Lit(P<Expr>),
Range(Option<P<Expr>>, Option<P<Expr>>, Spanned<RangeEnd>),
Slice(ThinVec<P<Pat>>),
Rest,
Never,
Paren(P<Pat>),
MacCall(P<MacCall>),
Err(ErrorGuaranteed),
}
Expand description
All the different flavors of pattern that Rust recognizes.
Variants§
Wild
Represents a wildcard pattern (_
).
Ident(BindingAnnotation, Ident, Option<P<Pat>>)
A PatKind::Ident
may either be a new bound variable (ref mut binding @ OPT_SUBPATTERN
),
or a unit struct/variant pattern, or a const pattern (in the last two cases the third
field must be None
). Disambiguation cannot be done with parser alone, so it happens
during name resolution.
Struct(Option<P<QSelf>>, Path, ThinVec<PatField>, PatFieldsRest)
A struct or struct variant pattern (e.g., Variant {x, y, ..}
).
TupleStruct(Option<P<QSelf>>, Path, ThinVec<P<Pat>>)
A tuple struct/variant pattern (Variant(x, y, .., z)
).
Or(ThinVec<P<Pat>>)
An or-pattern A | B | C
.
Invariant: pats.len() >= 2
.
Path(Option<P<QSelf>>, Path)
A possibly qualified path pattern.
Unqualified path patterns A::B::C
can legally refer to variants, structs, constants
or associated constants. Qualified path patterns <A>::B::C
/<A as Trait>::B::C
can
only legally refer to associated constants.
Tuple(ThinVec<P<Pat>>)
A tuple pattern ((a, b)
).
Box(P<Pat>)
A box
pattern.
Ref(P<Pat>, Mutability)
A reference pattern (e.g., &mut (a, b)
).
Lit(P<Expr>)
A literal.
Range(Option<P<Expr>>, Option<P<Expr>>, Spanned<RangeEnd>)
A range pattern (e.g., 1...2
, 1..2
, 1..
, ..2
, 1..=2
, ..=2
).
Slice(ThinVec<P<Pat>>)
A slice pattern [a, b, c]
.
Rest
A rest pattern ..
.
Syntactically it is valid anywhere.
Semantically however, it only has meaning immediately inside:
- a slice pattern:
[a, .., b]
, - a binding pattern immediately inside a slice pattern:
[a, r @ ..]
, - a tuple pattern:
(a, .., b)
, - a tuple struct/variant pattern:
$path(a, .., b)
.
In all of these cases, an additional restriction applies, only one rest pattern may occur in the pattern sequences.
Never
Paren(P<Pat>)
Parentheses in patterns used for grouping (i.e., (PAT)
).
MacCall(P<MacCall>)
A macro pattern; pre-expansion.
Err(ErrorGuaranteed)
Placeholder for a pattern that wasn’t syntactically well formed in some way.
Trait Implementations§
source§impl<__D: SpanDecoder> Decodable<__D> for PatKind
impl<__D: SpanDecoder> Decodable<__D> for PatKind
Auto Trait Implementations§
impl DynSend for PatKind
impl DynSync for PatKind
impl Freeze for PatKind
impl !RefUnwindSafe for PatKind
impl !Send for PatKind
impl !Sync for PatKind
impl Unpin for PatKind
impl !UnwindSafe for PatKind
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
impl<'a, T> Captures<'a> for Twhere
T: ?Sized,
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 48 bytes
Size for each variant:
Wild
: 0 bytesIdent
: 23 bytesStruct
: 47 bytesTupleStruct
: 47 bytesOr
: 15 bytesPath
: 39 bytesTuple
: 15 bytesBox
: 15 bytesRef
: 15 bytesLit
: 15 bytesRange
: 31 bytesSlice
: 15 bytesRest
: 0 bytesNever
: 0 bytesParen
: 15 bytesMacCall
: 15 bytesErr
: 0 bytes