Skip to content

Commit

Permalink
Rollup merge of rust-lang#44466 - clarcharr:cow_error, r=alexcrichton
Browse files Browse the repository at this point in the history
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()`.
  • Loading branch information
alexcrichton authored Sep 18, 2017
2 parents 2ab4840 + 778d5f2 commit 0a3de32
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/libstd/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@

use alloc::allocator;
use any::TypeId;
use borrow::Cow;
use cell;
use char;
use fmt::{self, Debug, Display};
Expand Down Expand Up @@ -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 }
Expand Down

0 comments on commit 0a3de32

Please sign in to comment.