pub enum Pattern {
Literal(LiteralPattern),
Wildcard,
Binding(String),
EnumVariant {
namespace: Option<String>,
type_name: String,
variant: String,
payload: VariantPatternPayload,
},
Struct {
namespace: Option<String>,
type_name: String,
fields: Vec<(String, Pattern)>,
rest: bool,
},
Array {
elements: Vec<Pattern>,
rest: Option<ArrayRest>,
},
Or(Vec<Pattern>),
}Expand description
A pattern in a match arm. Structurally mirrors the runtime Value enum
so each variant’s matcher reads as “does this value fit here?”.
Variants§
Literal(LiteralPattern)
Matches a specific value verbatim: 1, "foo", true,
false, none.
Wildcard
_ — matches anything, binds nothing.
Binding(String)
Value-shaped bare identifier — matches anything, binds the value to this name for the arm’s body.
EnumVariant
Type::Variant / Type::Variant(...) / Type::Variant { ... },
optionally namespaced via ns.Type::Variant(...).
Struct
Type { field: pat, field, .. } destructures a struct,
optionally namespaced via ns.Type { ... }.
Array
[a, b, ..rest] destructures an array.
Or(Vec<Pattern>)
p1 | p2 | p3 — match if any alternative matches. Every
alternative must introduce the same set of bindings.
Implementations§
Source§impl Pattern
impl Pattern
Sourcepub fn binding_names(&self) -> BTreeSet<String>
pub fn binding_names(&self) -> BTreeSet<String>
Return every value binding introduced by this pattern in stable name order. Duplicate occurrences collapse to one name; valid or-patterns therefore expose the same set regardless of alternative order or shape.
Sourcepub fn namespace_names(&self) -> BTreeSet<String>
pub fn namespace_names(&self) -> BTreeSet<String>
Return every namespace identifier used by a namespaced type pattern, including references nested inside tuple/struct/array/or patterns.