Skip to content

Commit

Permalink
Change Value::Error to &(dyn Error + 'static) (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e authored Oct 8, 2021
1 parent 48c623f commit acd1a7e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
7 changes: 7 additions & 0 deletions tests/tests/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,13 @@ fn test_error() {
let error: io::Error = io::ErrorKind::Other.into();
let error: &dyn error::Error = &error;
assert_value!(&'a dyn error::Error: Error, as_error, yes => error);

assert!(error
.as_value()
.as_error()
.unwrap()
.downcast_ref::<io::Error>()
.is_some()); // Check that Value::Error downcast-able
}

test_num! {
Expand Down
2 changes: 1 addition & 1 deletion valuable/src/valuable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ impl Valuable for std::path::PathBuf {
}

#[cfg(feature = "std")]
impl Valuable for dyn std::error::Error + '_ {
impl Valuable for dyn std::error::Error + 'static {
fn as_value(&self) -> Value<'_> {
Value::Error(self)
}
Expand Down
4 changes: 2 additions & 2 deletions valuable/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ value! {
/// let v = Value::Error(&err);
/// ```
#[cfg(feature = "std")]
Error(&'a dyn std::error::Error),
Error(&'a (dyn std::error::Error +'static)),

/// A Rust list value
///
Expand Down Expand Up @@ -574,7 +574,7 @@ macro_rules! convert {
/// assert!(Value::Bool(true).as_error().is_none());
/// ```
#[cfg(feature = "std")]
pub fn as_error(&self) -> Option<&dyn std::error::Error> {
pub fn as_error(&self) -> Option<&(dyn std::error::Error + 'static)> {
match *self {
Value::Error(v) => Some(v),
_ => None,
Expand Down

0 comments on commit acd1a7e

Please sign in to comment.