|
|
|
|
|
by exrook
1950 days ago
|
|
I'm confused, have you found the try operator ("?") insufficient for your use cases? I believe it does what you are describing, ex: fn process_file(p: Path) -> Result<String, io::Error> {
let file = File::open(p)?; //Return err if file can't be opened
let mut out = String::new();
file.read_to_string(&mut out)?; // Return err if read fails
out
}
If you want to handle the error case within the same function `try` blocks are available in nightly[0] and will eventually come to stable[1][0] https://doc.rust-lang.org/nightly/unstable-book/language-fea... [1] https://github.com/rust-lang/rust/issues/31436 |
|