Result Type
ELI5 — The Vibe Check
Result type is like a delivery that's either your package (Ok) or a note explaining why it failed (Err). You MUST check which one you got before proceeding. No more pretending errors don't exist!
Real Talk
A sum type representing either a successful value (Ok/Success) or an error (Err/Failure), used as a type-safe alternative to exceptions. Result types force explicit error handling at the type level, making failure paths visible in function signatures. Core to Rust, and increasingly adopted via libraries in TypeScript and other languages.
Show Me The Code
// Rust
fn parse_age(input: &str) -> Result<u32, String> {
input.parse::<u32>()
.map_err(|_| format!("'{}' is not a number", input))
}
let age = parse_age("25")?; // ? propagates errors
When You'll Hear This
"Result<T, E> makes errors part of the type signature — no hidden exceptions." / "The ? operator in Rust makes working with Result types ergonomic and clean."
Related Terms
Error Handling
Error handling is the art of planning for things to go wrong and dealing with them gracefully instead of letting everything catch fire.
Option Type
Option type is the type system's way of saying 'this might have a value, or it might be empty, and you MUST handle both cases.
Sum Type
A sum type is 'this thing is EITHER a cat OR a dog OR a fish — pick one.' It's like a multiple choice question for types.
Try/Catch
Try/catch is your safety net. You put risky code in the 'try' box, and if it blows up, the 'catch' box catches the explosion and handles it gracefully inst...