Skip to content
This repository was archived by the owner on Aug 16, 2021. It is now read-only.

Add Error::from_std method #159

Closed
wants to merge 1 commit into from

Conversation

matklad
Copy link
Contributor

@matklad matklad commented Feb 8, 2018

This method allows to convert from Boxstd::error::Error to Error.
Conversion in the opposite direction could be achieved with the Compat
struct

closes #158

Couple of questions:

  • should we add from_std_sync for Box<std::error::Error + Send + !Sync>?
  • is there a better name for this method?

@matklad matklad force-pushed the from_std branch 3 times, most recently from 4856650 to fab7824 Compare February 8, 2018 23:37
@matklad
Copy link
Contributor Author

matklad commented Feb 9, 2018

Hm, actually, the std has this impl:

impl<T: Error> Error for Box<T>

It seems to me that if we change this to

impl<T: Error + ?Sized> Error for Box<T>

than .into() would just work.

I've tried to figure out why there is no ?Sized bound there, and looks like it does not work, but nobody knows why?

rust-lang/rust#30796 (comment)

@matklad
Copy link
Contributor Author

matklad commented Feb 9, 2018

Ok, I've tried to add ?Sized bound to std, and I've hit overlapping impls for

impl From<Box<StdError>> for Box<StdError>

One impl is the trivial reflexive impl, another impl is impl <E: StdError> From<E> for Box<StdError>. Looks like we'll need specialization to sort this out =/

@withoutboats
Copy link
Contributor

Yea, its the same issue that means Error doesn't implement Fail here. My conclusion from this is that reusing the general conversion traits for ?-conversion was a mistake & we should have had a separate, specific trait.

I don't love the name from_std, it seems like "breaking the fourth wall" to mention std in a function name. Not sure what else to call it though..

@matklad
Copy link
Contributor Author

matklad commented Feb 10, 2018

As for naming, could we build on compat intuition? Error::from_compat or Error::compat_from?

@sanmai-NL
Copy link

Agree with https://github.com/withoutboats/failure/pull/159#issuecomment-364570531 on distaste for the from_std name.

@withoutboats
Copy link
Contributor

I can't think of anything better than from_compat. Something along those lines seems right.

This method allows to convert from Box<std::error::Error> to Error.
Conversion in the opposite direction could be achieved with the `Compat`
struct
@matklad
Copy link
Contributor Author

matklad commented Feb 18, 2018

Renamed to from_compat!

@slyphon
Copy link

slyphon commented Jul 5, 2018

bump!

I just ran into this issue, would love to know if it's still active

@mitsuhiko mitsuhiko closed this in 6cf63e0 Jul 27, 2018
@mitsuhiko
Copy link
Contributor

I pulled this in now but I renamed the method to from_boxed_compat.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How to conver from Box<Error> into failure::Error?
5 participants