Skip to main content

Module pattern_gen

Module pattern_gen 

Source
Expand description

Pattern matching generation from tag checks (DECY-082).

Transforms C tagged union access patterns (if-else-if chains checking tag fields) into safe Rust match expressions with exhaustive pattern matching.

§Transformation

C code:

if (v.tag == INT) {
    return v.data.i;
} else if (v.tag == FLOAT) {
    return v.data.f;
} else {
    return -1;
}

Rust code:

match v {
    Value::Int(i) => return i,
    Value::Float(f) => return f,
    _ => return -1,
}

§Benefits

  • Type safety: Compiler verifies correct variant access
  • Exhaustiveness: All possible cases must be handled
  • Zero unsafe: No unsafe union field access
  • Pattern binding: Direct access to variant payloads

Structs§

PatternGenerator
Generator for Rust pattern matching from C tag checks.