diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2017-09-18 11:04:20 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-09-18 11:04:20 -0500 |
| commit | fbf3b8ab8ea98ccc14423cb376a62de6f207fb3e (patch) | |
| tree | 0dda65bbd4a68569553c39e98d691bfd23ff62c9 /src | |
| parent | 9ad547367259407abccfc29ce684bda61b346d9f (diff) | |
| parent | 778d5f2074b05c013e15fabc25daf4e37a174bf7 (diff) | |
| download | rust-fbf3b8ab8ea98ccc14423cb376a62de6f207fb3e.tar.gz rust-fbf3b8ab8ea98ccc14423cb376a62de6f207fb3e.zip | |
Rollup merge of #44466 - clarcharr:cow_error, r=alexcrichton
Add Cow<str> -> Box<Error> impls. Considering how impls exist for `String` and `&str`, it makes sense to also add an impl for `Cow<str>` as well. This would allow converting `String::from_utf8_lossy` directly into a `Box<Error>` or `io::Error` without having to add an extra `into_ownd()`.
Diffstat (limited to 'src')
| -rw-r--r-- | src/libstd/error.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/libstd/error.rs b/src/libstd/error.rs index 401552a6ec4..6d64ea0d503 100644 --- a/src/libstd/error.rs +++ b/src/libstd/error.rs @@ -53,6 +53,7 @@ use alloc::allocator; use any::TypeId; +use borrow::Cow; use cell; use char; use fmt::{self, Debug, Display}; @@ -217,6 +218,20 @@ impl<'a> From<&'a str> for Box<Error> { } } +#[stable(feature = "cow_box_error", since = "1.22.0")] +impl<'a, 'b> From<Cow<'b, str>> for Box<Error + Send + Sync + 'a> { + fn from(err: Cow<'b, str>) -> Box<Error + Send + Sync + 'a> { + From::from(String::from(err)) + } +} + +#[stable(feature = "cow_box_error", since = "1.22.0")] +impl<'a> From<Cow<'a, str>> for Box<Error> { + fn from(err: Cow<'a, str>) -> Box<Error> { + From::from(String::from(err)) + } +} + #[unstable(feature = "never_type_impls", issue = "35121")] impl Error for ! { fn description(&self) -> &str { *self } |
