Skip to main content

Pattern

Enum Pattern 

Source
pub enum Pattern {
    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>),
    List(Vec<Pattern>, Rest),
    Map(Vec<(MapKey, Pattern)>, Rest),
}
Expand description

A pattern: the left-hand side of any binding (&<pat> …, let (<pat> = …), a __match clause). Matched against a value by the evaluator’s native matcher (match_pattern in eval.rs), which either extends the environment or refutes. Bind/Discard are irrefutable; every other shape may refute.

Variants§

§

Discard

_ — matches anything, binds nothing.

§

Bind(Text)

name — binds the subject to name. The matcher conses one cell carrying the subject onto the environment; the name itself is not stored at runtime (references to it were resolved to a de Bruijn index).

§

At(Text, Box<Pattern>)

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

§

Equal(Expr)

= <expr> (and its .sym sugar) — matches iff the subject equals the value of <expr>; binds nothing. Evaluating <expr> may raise a real error, which propagates (it is not a refutation).

§

Less(Expr)

< <expr> — matches iff the subject is (strictly) ordered before the value of <expr>; binds nothing. Ordering is defined only within a comparable kind (Int for now, later Str), so a subject/bound that are not both of one such kind refute with .not_int (a refutation, not a host raise).

§

Greater(Expr)

> <expr> — the mirror of Less: matches iff the subject is ordered after the value of <expr>.

§

Type(ProtoRef, Box<Pattern>)

<pat> as <Proto> / (as <Proto>) <pat> — matches iff the subject’s prototype is <Proto>, then matches <pat> against the (narrowed) subject. See ProtoRef for the two forms the prototype takes.

§

Unwrap

__value <pat> — matches iff the subject is an object of the home module and its payload matches <pat>, binding what the inner pattern binds. It is the pattern side of the __value leaf, and the prototype check is implicit for the same reason the leaf’s is: unwrapping a foreign object has no sound reading.

It holds no reference — the module is implicit, exactly as it is for __new — so the pattern grammar stays closed. depth is the leaf’s, and the matcher walks the environment to that terminal and compares the prototype by pointer before descending.

Fields

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

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

(p1 | p2) — try the left arm, on refutation try the right. Both arms bind the same set of names (checked at parse time). Committed: once an arm’s pattern matches, a later failure does not backtrack into the other arm.

§

List(Vec<Pattern>, Rest)

[p0, …] with an optional trailing rest — a fixed-arity list pattern.

§

Map(Vec<(MapKey, Pattern)>, Rest)

{ k0: p0, … } — a map pattern of (key, value pattern) entries. Rest::None is closed (exactly these keys); Rest::Anon/Named open it (at least these keys; Named binds the remainder map).

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 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 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
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.