pub enum Pattern {
Wildcard,
Var(String),
Literal(Literal),
Tuple(Vec<Pattern>),
Variant {
variant: String,
patterns: Vec<Pattern>,
},
}Expand description
Pattern in a match expression.
Patterns can match literals, variables, wildcards, tuples, and DU variants. Issue #27 supports basic patterns; Issue #28 will add lists/arrays.
Variants§
Wildcard
Wildcard pattern (_) - matches anything
Var(String)
Variable pattern (x) - binds matched value to variable
Literal(Literal)
Literal pattern (42, true, “hello”) - matches exact value
Tuple(Vec<Pattern>)
Tuple pattern ((p1, p2, …)) - matches tuples
Variant
Variant pattern (Some(x), Left, Circle(r)) - matches DU constructors
Implementations§
Source§impl Pattern
impl Pattern
Sourcepub fn is_wildcard(&self) -> bool
pub fn is_wildcard(&self) -> bool
Returns true if this pattern is a wildcard.
Sourcepub fn is_literal(&self) -> bool
pub fn is_literal(&self) -> bool
Returns true if this pattern is a literal.
Sourcepub fn as_var(&self) -> Option<&str>
pub fn as_var(&self) -> Option<&str>
Returns the variable name if this is a Var, otherwise None.
Sourcepub fn as_literal(&self) -> Option<&Literal>
pub fn as_literal(&self) -> Option<&Literal>
Returns the literal value if this is a Literal, otherwise None.
Sourcepub fn as_tuple(&self) -> Option<&Vec<Pattern>>
pub fn as_tuple(&self) -> Option<&Vec<Pattern>>
Returns the tuple patterns if this is a Tuple, otherwise None.
Sourcepub fn is_variant(&self) -> bool
pub fn is_variant(&self) -> bool
Returns true if this pattern is a variant.
Trait Implementations§
impl StructuralPartialEq for Pattern
Auto Trait Implementations§
impl Freeze for Pattern
impl RefUnwindSafe for Pattern
impl Send for Pattern
impl Sync for Pattern
impl Unpin for Pattern
impl UnwindSafe for Pattern
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
🔬This is a nightly-only experimental API. (
clone_to_uninit)