diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:03:36 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:03:36 +0000 |
commit | 17d40c6057c88f4c432b0d7bac88e1b84cb7e67f (patch) | |
tree | 3f66c4a5918660bb8a758ab6cda5ff8ee4f6cdcd /vendor/quick-error/examples/context.rs | |
parent | Adding upstream version 1.64.0+dfsg1. (diff) | |
download | rustc-17d40c6057c88f4c432b0d7bac88e1b84cb7e67f.tar.xz rustc-17d40c6057c88f4c432b0d7bac88e1b84cb7e67f.zip |
Adding upstream version 1.65.0+dfsg1.upstream/1.65.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | vendor/quick-error/examples/context.rs | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/vendor/quick-error/examples/context.rs b/vendor/quick-error/examples/context.rs index 1d406613e..334700a03 100644 --- a/vendor/quick-error/examples/context.rs +++ b/vendor/quick-error/examples/context.rs @@ -1,14 +1,19 @@ -use quick_error::{quick_error, ResultExt}; -use std::env; -use std::fs::File; +#[macro_use(quick_error)] extern crate quick_error; + use std::io::{self, stderr, Read, Write}; +use std::fs::File; +use std::env; use std::num::ParseIntError; use std::path::{Path, PathBuf}; +use quick_error::ResultExt; + quick_error! { #[derive(Debug)] pub enum Error { - NoFileName {} + NoFileName { + description("no file name specified") + } Io(err: io::Error, path: PathBuf) { display("could not read file {:?}: {}", path, err) context(path: &'a Path, err: io::Error) @@ -23,12 +28,12 @@ quick_error! { } fn parse_file() -> Result<u64, Error> { - let fname = env::args().skip(1).next().ok_or(Error::NoFileName)?; + let fname = try!(env::args().skip(1).next().ok_or(Error::NoFileName)); let fname = Path::new(&fname); - let mut file = File::open(fname).context(fname)?; + let mut file = try!(File::open(fname).context(fname)); let mut buf = String::new(); - file.read_to_string(&mut buf).context(fname)?; - Ok(buf.parse().context(fname)?) + try!(file.read_to_string(&mut buf).context(fname)); + Ok(try!(buf.parse().context(fname))) } fn main() { |