Back to course

Option & Result: Error Handling

Rust for Systems & Web3 Security

No More Nulls

Rust does not have a null value. Instead, it uses the Option enum:

rust enum Option { Some(T), None, }

Recoverable Errors with Result

For operations that can fail (like opening a file), Rust uses Result:

rust enum Result<T, E> { Ok(T), Err(E), }

Using the ? operator allows you to propagate errors easily. This is vital in Web3 to handle failed transactions or invalid signatures without crashing the node.