Pattern

Enum Pattern 

Source
pub enum Pattern {
    Wildcard,
    Bind(VarId),
    Const(Const),
    Ctor {
        variant: Arc<str>,
        binds: Vec<(Arc<str>, Pattern)>,
    },
    At {
        var: VarId,
        inner: Box<Pattern>,
    },
    Or(Vec<Pattern>),
    List {
        items: Vec<Pattern>,
        rest: Option<Option<VarId>>,
    },
}

Variants§

§

Wildcard

§

Bind(VarId)

§

Const(Const)

§

Ctor

Added(id, text)variant names the constructor, and each field carries the pattern matched against it.

A field’s pattern is usually a Pattern::Bind or a Pattern::Wildcard, which is what Added(id, text) and Added(_) mean. It may be any pattern: Some(Added(id, text)) is a Ctor whose one field is a Ctor.

Fields

§variant: Arc<str>
§binds: Vec<(Arc<str>, Pattern)>
§

At

whole @ Circle(r) — a name for the value, and a pattern that takes it apart.

The binder is irrefutable, so whether this matches is entirely inner’s question.

Fields

§var: VarId
§inner: Box<Pattern>
§

Or(Vec<Pattern>)

Circle(r) | Square(r) — one of several, and every alternative binds the same names.

The checker unifies the alternatives’ binders onto one set of variables, so the body reads r without knowing which alternative matched. That is the rule that makes an or-pattern a pattern rather than two arms sharing a body.

§

List

[], [x], [a, b], [first, *rest] — a list, taken apart.

items is one pattern per fixed element and rest is the optional tail binder. A pattern with no rest matches a list of exactly items.len() elements; one with a rest matches any list at least that long.

The tail is a binder rather than a pattern, and deliberately: [a, *[b, c]] is [a, b, c] written twice over, so what it would add is a second spelling rather than a shape.

Fields

§items: Vec<Pattern>

Implementations§

Source§

impl Pattern

Source

pub fn binders(&self) -> Vec<VarId>

Every variable this pattern binds, at any depth.

One method rather than a match at each of the three call sites, because those three were Bind/Ctor/_ => {} — and a new pattern kind falling into the _ would have been a silent miscount in the splitter’s variable supply and a false free variable in the plan’s analysis. Neither would have failed a test until a program used one (docs/33 §33.5).

Source

pub fn irrefutable(&self) -> bool

Whether this pattern matches every value of its type, so that no arm after it can run.

Only a binder and a wildcard do — and a list pattern of nothing but a tail, [*rest], which is the one refutable-looking shape that refuses nothing.

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

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.