expression
Inject a sensor failure into a pure decision function
Firmware logic should distinguish a failed measurement from a genuine zero reading. This model selects a safe inactive state for an illustrative noncritical indicator when a reading fails. A real device must define its safe state from requirements and hazard analysis, not blindly turn everything off. Expected host stdout (not executed): fault cases passed Common mistake: Replacing all failures with zero and losing the distinction between an error and a measurement.
Formal Syntax & Structure
rust syntaxrust
Result<u16, SensorError>Working Example
Example Snippetrust
#![no_std]#[derive(Clone, Copy)]pub enum SensorError { Timeout, Invalid }pub fn indicator(reading: Result<u16, SensorError>) -> bool { matches!(reading, Ok(n) if n >= 50)}