Skip to main content

Pattern

Enum Pattern 

Source
pub enum Pattern {
    Wildcard(Span),
    Ident {
        is_mut: bool,
        name: Ident,
        span: Span,
    },
    Int(IntLit),
    NegInt(NegIntLit),
    Bool(BoolLit),
    Path(PathPattern),
    DataVariant {
        base: Option<Box<Expr>>,
        type_name: Ident,
        variant: Ident,
        fields: Vec<TupleElemPattern>,
        span: Span,
    },
    StructVariant {
        base: Option<Box<Expr>>,
        type_name: Ident,
        variant: Ident,
        fields: Vec<FieldPattern>,
        span: Span,
    },
    Struct {
        type_name: Ident,
        fields: Vec<FieldPattern>,
        span: Span,
    },
    Tuple {
        elems: Vec<TupleElemPattern>,
        span: Span,
    },
    ComptimeUnrollArm {
        binding: Ident,
        iterable: Box<Expr>,
        span: Span,
    },
}
Expand description

A pattern in a let binding or match arm (ADR-0049).

A single recursive Pattern type is used in both contexts. Sema enforces refutability per context (let requires irrefutable patterns, match accepts any).

Variants§

§

Wildcard(Span)

Wildcard pattern _ - matches anything, irrefutable

§

Ident

Named binding (x or mut x), irrefutable

Fields

§is_mut: bool
§name: Ident
§span: Span
§

Int(IntLit)

Integer literal pattern (positive or zero), refutable

§

NegInt(NegIntLit)

Negative integer literal pattern (e.g., -1, -42), refutable

§

Bool(BoolLit)

Boolean literal pattern, refutable

§

Path(PathPattern)

Path pattern (e.g., Color::Red for a unit enum variant), refutable

§

DataVariant

Data variant pattern with positional sub-patterns (e.g., Option::Some(x))

Fields

§base: Option<Box<Expr>>

Optional module prefix

§type_name: Ident

Enum type name

§variant: Ident

Variant name

§fields: Vec<TupleElemPattern>

Sub-patterns for each field (may include .. via TupleElemPattern::Rest)

§span: Span
§

StructVariant

Struct variant pattern with named field sub-patterns (e.g., Shape::Circle { radius })

Fields

§base: Option<Box<Expr>>

Optional module prefix

§type_name: Ident

Enum type name

§variant: Ident

Variant name

§fields: Vec<FieldPattern>

Named field sub-patterns (may include .. via a field with field_name: None)

§span: Span
§

Struct

Struct destructure pattern (e.g., Point { x, y }), irrefutable when all sub-patterns are.

Fields

§type_name: Ident

The struct type name (for anonymous structs, resolved via a local type alias)

§fields: Vec<FieldPattern>

Named field sub-patterns (may include ..)

§span: Span
§

Tuple

Tuple destructure pattern (e.g., (a, b) or (a, .., c)), irrefutable when all sub-patterns are.

Fields

§span: Span
§

ComptimeUnrollArm

ADR-0079 Phase 3: a comptime_unroll for arm template. Only valid at the top level of a match arm — sema rejects it elsewhere. The arm fires once per element of iterable; the compiler synthesizes a variant-specific concrete pattern per iteration and substitutes binding as a comptime value in the arm body.

Fields

§binding: Ident
§iterable: Box<Expr>
§span: Span

Implementations§

Source§

impl Pattern

Source

pub fn span(&self) -> Span

Get the span of this pattern.

Trait Implementations§

Source§

impl Clone for Pattern

Source§

fn clone(&self) -> Pattern

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 Debug for Pattern

Source§

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

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

impl<'de> Deserialize<'de> for Pattern

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Pattern

Source§

fn eq(&self, other: &Pattern) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Pattern

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for Pattern

Source§

impl StructuralPartialEq for Pattern

Auto Trait Implementations§

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
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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.

§

impl<'src, T> IntoMaybe<'src, T> for T
where T: 'src,

§

type Proj<U: 'src> = U

§

fn map_maybe<R>( self, _f: impl FnOnce(&'src T) -> &'src R, g: impl FnOnce(T) -> R, ) -> <T as IntoMaybe<'src, T>>::Proj<R>
where R: 'src,

§

impl<'p, T> Seq<'p, T> for T
where T: Clone,

§

type Item<'a> = &'a T where T: 'a

The item yielded by the iterator.
§

type Iter<'a> = Once<&'a T> where T: 'a

An iterator over the items within this container, by reference.
§

fn seq_iter(&self) -> <T as Seq<'p, T>>::Iter<'_>

Iterate over the elements of the container.
§

fn contains(&self, val: &T) -> bool
where T: PartialEq,

Check whether an item is contained within this sequence.
§

fn to_maybe_ref<'b>(item: <T as Seq<'p, T>>::Item<'b>) -> Maybe<T, &'p T>
where 'p: 'b,

Convert an item of the sequence into a [MaybeRef].
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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<T> OrderedSeq<'_, T> for T
where T: Clone,