Adding a from_unwrapped
method to the trait basically requires that an object implementing this trait must be reconstructible from its output type. In my Bail
example, it broke down because a Bail was always a T
, even when the T
would never be actually produced.
In the wild, this could break down if people want to implement the TryUnwrap
trait on objects that are "more than a bijection from Result
". Think Result
with state, for instance:
struct RemotePromise<T> {
connection: Connection,
request: Request,
_phantom: PhantomData<T>,
}
impl<T> TryUnwrap<Result<(), ConnectionError>> for RemotePromise<T> {
type Output = T;
fn try_unwrap(self) {
match self.connection.resolve_promise(self.request) {
Ok(result) => MaybeUnwrap::Unwrap(result),
Err(error) => MaybeUnwrap::Return(Err(error)),
}
}
fn from_unwrap(result: T) -> Self {
// cannot rebuild connection nor request from here.
}
}
Now, this example is still a bit contrived, because we could have a PromiseResult
inert object (like Future
has Poll
) and have that implement the TryUnwrap
type, so I'm not sure it is a good example. Besides, the perspective of being able to use ?
to perform network operations is a bit frightening.
I'm not sure it's worth it to lose the convenience of from_unwrapped
for such a niche case.
Need to think a little bit more about all of this
If anyone comes up with a better example, feel free to share!