Skip to main content

PatternKind

Enum PatternKind 

Source
pub enum PatternKind {
    Anything,
    Variable(Name),
    Int(i64),
    Float(f64),
    Char(char),
    String(String),
    Tuple(Tuple<Pattern>),
    Unit,
    Constructor {
        ctor: TypeConstructor,
        args: Vec<Pattern>,
    },
    Hole(Vec<Pattern>),
    Record(Vec<PatternField>),
}

Variants§

§

Anything

§

Variable(Name)

§

Int(i64)

§

Float(f64)

§

Char(char)

§

String(String)

§

Tuple(Tuple<Pattern>)

A tuple pattern. Zelkova keeps Elm’s restriction of two or three elements, which [Tuple] carries in its shape.

§

Unit

The unit pattern, (): it matches the one value of the unit type and binds nothing.

§

Constructor

Fields

§args: Vec<Pattern>
§

Hole(Vec<Pattern>)

A constructor pattern whose constructor did not resolve, with the patterns written as its arguments. The error saying so has been reported, or dropped in an incomplete scope, and the declaration is kept (DEC-23 decision 6).

The arguments are kept so that the names they bind are still in scope in the branch or the body the pattern governs, and a use of one there is not reported as a second missing name.

§

Record(Vec<PatternField>)

A record pattern, { label = pattern, … }: the fields it names, each with the pattern its value is matched against, in the order they were written. The { label } shorthand is not a form of its own: the grammar desugared it to label = label.

The entries name a subset of the record’s fields, so this is not the whole field set a Type::Record is, and it is not keyed by label the way that one is. No label appears twice — Pattern::from_parser reports a repeated one as Error::RepeatedLabel — and what the pattern matches does not depend on the order of its entries. They are kept as the source wrote them, as a tuple’s elements are, and ScopedEnvironment::expose_pattern walks them in that order. Each entry keeps its label’s span, which is where a diagnostic about that field points.

Refutable exactly when one of its entries’ patterns is ({ x } cannot fail, { x = 0 } can). Nothing here records that, and nothing may read a record pattern as irrefutable for being a record.

Trait Implementations§

Source§

impl Clone for PatternKind

Source§

fn clone(&self) -> PatternKind

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 PatternKind

Source§

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

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

impl PartialEq for PatternKind

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for PatternKind

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.