wscript: pattern matching & errors
Option[T] and Result[T,E] are built in; let-else, match (exhaustive), and ? are the idioms vmlab scripts live on.
Option[T] and Result[T, E] are built in. All fallible vmlab API calls return Result[..., string].
rust
// let-else: bail early (block must diverge — return/break)
let Ok = lab.vm else lab.log
return
}
// match (exhaustiveness-checked at compile time)
match dc.wait_ready Ok => lab.log,
Err =>
}
// ? propagates Err/None out of a function with a matching return type
let dc = lab.vm?
dc.wait_ready?
Ok
}
Methods: is_some is_none unwrap unwrap_or expect (Option) / is_ok is_err unwrap unwrap_or unwrap_err expect (Result).