The ? operator changed how I write Rust

    August 9, 20243 blocks

    Propagate, don't panic

    Early Rust code is full of match arms unwrapping results. The ? operator collapses that into a single readable line while keeping errors explicit.

    fn read_config(path: &str) -> Result<Config, Error> {
        let raw = std::fs::read_to_string(path)?;
        let cfg = toml::from_str(&raw)?;
        Ok(cfg)
    }