Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created July 22, 2019 06:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rust-play/26cce491505376bf8c6e0bf95f4c24a6 to your computer and use it in GitHub Desktop.
Save rust-play/26cce491505376bf8c6e0bf95f4c24a6 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
fn main() -> Result<(), Box<dyn std::fmt::Debug>> {
let contents =
std::fs::read_to_string("my.txt").map_err(|e| Box::new(e) as Box<dyn std::fmt::Debug>)?;
let number = contents
.parse::<i32>()
.map_err(|e| Box::new(e) as Box<dyn std::fmt::Debug>)?;
println!("Number is {}!", number);
return Ok(());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment