Skip to content

Result Type

Medium — good to knowGeneral Dev

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."

Made with passive-aggressive love by manoga.digital. Powered by Claude.