Skip to main content

Pattern

Enum Pattern 

Source
pub enum Pattern {
Show 13 variants Discard, Bind(Text), At(Text, Box<Pattern>), Equal(Expr), Less(Expr), Greater(Expr), Type(ProtoRef, Box<Pattern>), Unwrap { depth: u32, inner: Box<Pattern>, }, Or(Box<Pattern>, Box<Pattern>), Unit, List { elems: Vec<Pattern>, rest: Option<Box<Pattern>>, }, Map { entries: Vec<(MapKey, Pattern)>, rest: Option<Box<Pattern>>, }, When { inner: Box<Pattern>, when: (Option<Box<Pattern>>, Expr), },
}
Expand description

A pattern: the left-hand side of a binding (&<pat> …, let (<pat> = …), or a __match clause). Matched by the evaluator’s native matcher (match_pattern in eval.rs). Bind/Discard are irrefutable.

Variants§

§

Discard

_ — matches any value without binding.

§

Bind(Text)

name — binds the subject to name. A cell is consed onto the environment; names are resolved to de Bruijn indices at parse time.

§

At(Text, Box<Pattern>)

name = <pat> — binds the subject to name, then matches <pat> against the same subject.

§

Equal(Expr)

= <expr> — matches if the subject equals the value of <expr>. Evaluation errors propagate; they are not refutations.

§

Less(Expr)

< <expr> — matches if the subject is ordered before the value of <expr>. Only defined for comparable kinds (e.g., Int); others refute with .not_int.

§

Greater(Expr)

> <expr> — matches if the subject is ordered after the value of <expr>.

§

Type(ProtoRef, Box<Pattern>)

<pat> as <Proto> — matches if the subject’s prototype is <Proto>, then matches <pat> against the subject.

§

Unwrap

Self <pat> — matches if the subject is an object of the home module and its payload matches <pat>. Prototype check is implicit. depth is the distance to the home module terminal.

Fields

§depth: u32
§inner: Box<Pattern>
§

Or(Box<Pattern>, Box<Pattern>)

(p1 | p2) — tries arms sequentially. Both arms must bind the same names. Once an arm matches, the pattern is committed (no backtracking).

§

Unit

&() — matches only the unit value.

§

List

[p0, ...] list pattern. rest handles the remainder: None for exact arity, Some(Discard) for minimum arity, or Some(Bind(name)) to bind.

Fields

§elems: Vec<Pattern>
§

Map

{ k0: p0, ... } map pattern. rest handles the remainder similarly to lists.

Fields

§entries: Vec<(MapKey, Pattern)>
§

When

<pat> when (<cond>) guarded pattern. Matches inner, then the guard. Plain guards must be Bool; pattern guards match gpat against the condition.

Fields

§inner: Box<Pattern>

Trait Implementations§

Source§

impl Clone for Pattern

Source§

fn clone(&self) -> Pattern

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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 Eq for Pattern

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 (const: unstable) · 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 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
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.