Last active
February 18, 2023 14:26
-
-
Save darwinsubramaniam/d00195c4d6a665c955015a45266331c4 to your computer and use it in GitHub Desktop.
Rust: Dynamic Result Return
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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