Rust Core

Traits and Result

rust
trait Summarize {
    fn summary(&self) -> String;
}

fn read_config() -> Result<String, std::io::Error> {
    let data = std::fs::read_to_string("config.toml")?;
    Ok(data)
}

The ? operator propagates an error to the caller, making error-aware code concise without hiding failure.

Lesson complete?Use the next lesson to continue the learning path.