From 17d40c6057c88f4c432b0d7bac88e1b84cb7e67f Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:03:36 +0200 Subject: Adding upstream version 1.65.0+dfsg1. Signed-off-by: Daniel Baumann --- vendor/quick-error/examples/context.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'vendor/quick-error/examples/context.rs') 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 { - 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() { -- cgit v1.2.3