You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There's an implementation of From that allows the conversion of a String to a Box<Error + Send + Sync>, but it doesn't quite work when just using Box<Error>.
michael: ~ $ rustc -V
rustc 1.6.0-nightly (9303055f3 2015-11-19)
michael: ~ $ rustc test.rs
test.rs:9:26: 9:36 error: the trait `std::error::Error` is not implemented for the type `collections::string::String` [E0277]
test.rs:9 let e3: Box<Error> = From::from("hello".to_string());
^~~~~~~~~~
test.rs:9:26: 9:36 help: run `rustc --explain E0277` to see a detailed explanation
test.rs:9:26: 9:36 note: required by `core::convert::From::from`
error: aborting due to previous error
The (perhaps subtle) error message is due to the compiler attempting to use the general From<E: Error> implementation for Box<Error>.
Solutions and Workarounds
I was trying to return string errors from a function returning Result<_, Box<Error>> and ended up writing the following:
This works well, but is really just boilerplate and not obviously suited to inclusion in any crate or library. Other solutions I thought of include:
Adding impl From<String> for Box<Error> to the standard library for cases like this.
Altering the semantics for trait-resolution on types that parametrise over multiple traits. From what I've read, we don't yet have semantics for general additions of traits, only built-in ones. See E0225.
The text was updated successfully, but these errors were encountered:
There's an implementation of
From
that allows the conversion of aString
to aBox<Error + Send + Sync>
, but it doesn't quite work when just usingBox<Error>
.Code
Compiler Output
The (perhaps subtle) error message is due to the compiler attempting to use the general
From<E: Error>
implementation forBox<Error>
.Solutions and Workarounds
I was trying to return string errors from a function returning
Result<_, Box<Error>>
and ended up writing the following:This works well, but is really just boilerplate and not obviously suited to inclusion in any crate or library. Other solutions I thought of include:
impl From<String> for Box<Error>
to the standard library for cases like this.The text was updated successfully, but these errors were encountered: