#![feature(try_trait_v2)]
use std::{convert, ops::FromResidual};
// Already support
fn try_trait_v2_with_result<T: Default, E>() -> Result<T, E> {
let val = Ok(T::default())?;
Ok(T::default())
}
// Already support
fn try_trait_v2_with_option<T: Default>() -> Option<T> {
let val = Some(T::default())?;
Some(T::default())
}
// Now we want
fn we_want_try_trait_v2_with_result_and_option<T: Default, E>() -> Result<T, E> {
let val = Ok(T::default())?;
let val = Some(T::default())?;
Ok(T::default())
}
// ERROR: only traits defined in the current crate can be implemented for types defined outside of the crate
impl<T, E> FromResidual<Option<convert::Infallible>> for Result<T, E> {
fn from_residual(residual: Option<convert::Infallible>) -> Self {
todo!()
}
}
Solution sketch
Alternatives
Links and related work
What happens now?
This issue contains an API change proposal (or ACP) and is part of the libs-api team feature lifecycle. Once this issue is filed, the libs-api team will review open proposals as capability becomes available. Current response times do not have a clear estimate, but may be up to several months.
Possible responses
The libs team may respond in various different ways. First, the team will consider the problem (this doesn't require any concrete solution or alternatives to have been proposed):
We think this problem seems worth solving, and the standard library might be the right place to solve it.
We think that this probably doesn't belong in the standard library.
Second, if there's a concrete solution:
We think this specific solution looks roughly right, approved, you or someone else should implement this. (Further review will still happen on the subsequent implementation PR.)
We're not sure this is the right solution, and the alternatives or other materials don't give us enough information to be sure about that. Here are some questions we have that aren't answered, or rough ideas about alternatives we'd want to see discussed.
Proposal
Problem statement
Motivating examples or use cases
Solution sketch
Alternatives
Links and related work
What happens now?
This issue contains an API change proposal (or ACP) and is part of the libs-api team feature lifecycle. Once this issue is filed, the libs-api team will review open proposals as capability becomes available. Current response times do not have a clear estimate, but may be up to several months.
Possible responses
The libs team may respond in various different ways. First, the team will consider the problem (this doesn't require any concrete solution or alternatives to have been proposed):
Second, if there's a concrete solution: