Skip to content

Instantly share code, notes, and snippets.

@darwinsubramaniam
Last active February 18, 2023 14:26
Show Gist options
  • Save darwinsubramaniam/d00195c4d6a665c955015a45266331c4 to your computer and use it in GitHub Desktop.
Save darwinsubramaniam/d00195c4d6a665c955015a45266331c4 to your computer and use it in GitHub Desktop.
Rust: Dynamic Result Return
// Adding this line
type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
// as the example
async main() -> Result<int> {
let mut args = std::env::args();
let _ = args.next();
let path = args.next().expect("missing path argument");
let mut file = File::open(path).await?;
let mut contents = Vec::new();
file.read_to_end(&mut contents).await?;
println!("file contents: {:?}", contents);
Ok(3)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment