1
Fork 0

Add an impl for Box<Error> from &str.

This commit is contained in:
Michael Sproul 2016-01-13 10:38:25 +11:00
parent 9520354115
commit c1e527f11d
2 changed files with 9 additions and 0 deletions

View file

@ -135,6 +135,13 @@ impl<'a, 'b> From<&'b str> for Box<Error + Send + Sync + 'a> {
} }
} }
#[stable(feature = "string_box_error", since = "1.7.0")]
impl<'a> From<&'a str> for Box<Error> {
fn from(err: &'a str) -> Box<Error> {
From::from(String::from(err))
}
}
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl Error for str::ParseBoolError { impl Error for str::ParseBoolError {
fn description(&self) -> &str { "failed to parse bool" } fn description(&self) -> &str { "failed to parse bool" }

View file

@ -15,4 +15,6 @@ use std::error::Error;
fn main() { fn main() {
let _err1: Box<Error + Send + Sync> = From::from("test".to_string()); let _err1: Box<Error + Send + Sync> = From::from("test".to_string());
let _err2: Box<Error> = From::from("test".to_string()); let _err2: Box<Error> = From::from("test".to_string());
let _err3: Box<Error + Send + Sync + 'static> = From::from("test");
let _err4: Box<Error> = From::from("test");
} }