Open l4l opened 1 year ago
any reason why it doesn't exist?
The big one would be that using a trait for build
or fail
would require the user to import that trait first. That's not insurmountable, but it's an annoying papercut. If "inherent traits" were a thing, then this would be an easy win.
Without that, the next best thing would be some kind of adjacent implementation, e.g.
struct X;
impl X {
fn foo() {}
}
trait TheFooTrait {
fn foo_from_trait();
}
impl TheFooTrait for X {
fn foo_from_trait() { self.foo() }
}
Note that this is also annoying as there are different names (IIRC this is required because you can't disambiguate a trait and inherent method of the same name).
captures some implicit context
Would #[snafu(implicit)]
help?
In cases where I've wanted to be generic over selectors, I usually end up using the IntoError
trait. Note that you may need to use NoneError
for your case.
I want to wrap a snafu-managed error with mine that captures some implicit context. Basically I do smth like this:
Then in the code I have statements like this
return XyzSnafu { .. }.fail().into()
. Basically I want to combine thatfail() + into()
(and similarly for build) into a single call, e.g:But here's the problem, there's no generic type bound to implement it for and use fail/build in implementation. So is there any reason why it doesn't exist?