// Created on savesnippets.com · https://savesnippets.com/ArbhPsXYqHxEXd use std::error::Error; use std::fs; fn read_first_line(path: &str) -> Result> { let contents = fs::read_to_string(path)?; // io::Error → Box let line = contents.lines().next() .ok_or("file was empty")?; // &str → Box Ok(line.to_string()) } fn main() -> Result<(), Box> { let first = read_first_line("Cargo.toml")?; println!("first line: {first}"); Ok(()) }