Skip to main content

match_pattern

Function match_pattern 

Source
pub fn match_pattern(
    pat: &Pattern,
    value: &Value,
    bindings: &mut Vec<Value>,
) -> bool
Expand description

Structural pattern matching against an already-evaluated scrutinee. Returns true (and appends every bound value, POSITIONALLY, in the order they were encountered) on a structural match; returns false (leaving bindings for this attempt unusable — callers must use a fresh Vec per arm) otherwise.

The push order here is the same left-to-right traversal compile::pattern_vars uses to collect the arm’s names, so position i in bindings is slot i of the frame the arm runs in — keep the two in step. A pattern/value shape mismatch is simply “no match”, never an error: this untyped evaluator relies on the separate exhaustiveness/type checker to rule out ill-typed matches ahead of time.