Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Fallibility in Signatures

Three return shapes, three meanings:

ShapeMeaning
Tā€œThis doesn’t failā€, or ā€œfailure here’s a bug, and a documented oneā€. The reviewer should believe it or flag it.
Option<T>ā€œAbsence is a normal outcome.ā€ Lookup misses, exhausted iterators.
Result<T, E>ā€œThis can fail, and E says how.ā€

Panics are a fourth shape. A documented panic on a violated precondition is a legitimate contract: slice indexing works this way, and so does RefCell::borrow. A function that returns T but panics on ordinary input has a dishonest signature: that failure path belongs in the type.

Absence or failure?

The same operation can be modeled either way:

fn signal(&self, name: &str) -> Option<&SignalDef>;               // a miss is normal
fn signal(&self, name: &str) -> Result<&SignalDef, UnknownSignal>; // a miss is a defect

Which is right depends on the callers: do they probe for signals that may not exist, or do they name signals that must exist? Decide this in the skeleton. If you don’t, the agent decides it for you, module by module, with no guarantee the modules agree.