From 3017f2a2ff9e1243765a884dcfcc10b89adaf681 Mon Sep 17 00:00:00 2001 From: Toby Smith Date: Mon, 30 Jul 2018 12:38:39 +1000 Subject: [PATCH 1/2] wip: trial a boxed exitdisplay instead of exitdisplay --- examples/display.rs | 6 +++--- src/lib.rs | 23 ++++++++++++++--------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/examples/display.rs b/examples/display.rs index a9189f1..be67c1b 100644 --- a/examples/display.rs +++ b/examples/display.rs @@ -2,10 +2,10 @@ extern crate exitfailure; use exitfailure::ExitDisplay; -fn main() -> Result<(), ExitDisplay> { +fn main() -> Result<(), ExitDisplay> { Ok(some_fn()?) } -fn some_fn() -> Result<(), String> { - Err("this is an error message".into()) +fn some_fn() -> Result<(), impl std::fmt::Display> { + Err("this is an error message") } diff --git a/src/lib.rs b/src/lib.rs index 075a8fe..b4102ec 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -86,26 +86,31 @@ impl> From for ExitFailure { /// ```rust,should_panic /// # extern crate exitfailure; /// # use exitfailure::ExitDisplay; -/// fn main() -> Result<(), ExitDisplay> { +/// fn main() -> Result<(), ExitDisplay> { +/// some_other_fn()?; /// Ok(some_fn()?) /// } /// -/// fn some_fn() -> Result<(), String> { -/// Err("some error".into()) +/// fn some_fn() -> Result<(), &'static str> { +/// Err("some error") +/// } +/// +/// fn some_other_fn() -> Result<(), isize> { +/// Ok(()) /// } /// ``` -pub struct ExitDisplay(E); +pub struct ExitDisplay(Box); /// Prints the underlying error type, using `Display` and not `Debug`. -impl std::fmt::Debug for ExitDisplay { +impl std::fmt::Debug for ExitDisplay { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", self.0) } } -impl From for ExitDisplay { +impl From for ExitDisplay { fn from(e: E) -> Self { - ExitDisplay(e) + ExitDisplay(Box::new(e)) } } @@ -127,8 +132,8 @@ mod test { #[test] fn test_exitdisplay() { let mut buffer = String::new(); - let error = "some error".to_string(); - let exitdisplay: ExitDisplay = error.into(); + let error = "some error"; + let exitdisplay: ExitDisplay = error.into(); write!(buffer, "{:?}", exitdisplay).unwrap(); assert_eq!(buffer, "some error"); } From deafec70b696c646887a68e05d3fd8f3531af687 Mon Sep 17 00:00:00 2001 From: Toby Smith Date: Sun, 12 Aug 2018 08:54:01 +1000 Subject: [PATCH 2/2] build: update minimum supported release I wanted to use `dyn Trait` syntax in ExitDisplay --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 35fd0b6..1abee2e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ rust: - stable - beta - nightly - - 1.26.0 #oldest supported release + - 1.27.0 #oldest supported release matrix: fast_finish: true