Match
Exhaustive match supports qualified variants, tuple bindings, wildcard, and explicit move or borrow modes.
DByte 12.0 · Language
Contract§
fn add_two(input: Result[u32, u32]) -> Result[u32, u32]:
let value = input?
return Result[u32, u32].Ok(value + (2 as u32))
pub fn kernel_main() -> int:
let result = add_two(Result[u32, u32].Ok(40 as u32))
match result:
case Result.Ok(value):
if value != (42 as u32):
return 1
case Result.Err(error):
return error as int
return 0
Source: source-examples/v12.0.0/result_match.dby
fn add_two(input: Result[u32, u32]) -> Result[u32, u32]:
let value = input?
return Result[u32, u32].Ok(value + (2 as u32))
pub fn kernel_main() -> int:
let result = add_two(Result[u32, u32].Ok(40 as u32))
match result:
case Result.Ok(value):
if value != (42 as u32):
return 1
case Result.Err(error):
return error as int
return 0
Mechanics§
Canonical match stores the discriminant place, resolved variant arms, bindings and an unreachable default after exhaustiveness succeeds. match moves non-Copy payloads; match borrow and match borrow mut establish the selected borrow mode.
Validation and failure§
Missing variants, duplicate coverage, incompatible bindings and illegal borrow actions fail before lowering. Version 12 has no guards or named payload patterns.
Evidence and boundary§
HIR snapshots expose resolved arms while the shared parity corpus compares selected values and error behavior on every engine.
Executable example§
fn add_two(input: Result[u32, u32]) -> Result[u32, u32]:
let value = input?
return Result[u32, u32].Ok(value + (2 as u32))
pub fn kernel_main() -> int:
let result = add_two(Result[u32, u32].Ok(40 as u32))
match result:
case Result.Ok(value):
if value != (42 as u32):
return 1
case Result.Err(error):
return error as int
return 0The website fixture demonstrates exhaustive Result variant matching and ? propagation together.