-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-error-handlingArea: Error handlingArea: Error handlingB-RFC-implementedBlocker: Approved by a merged RFC and implemented but not stabilized.Blocker: Approved by a merged RFC and implemented but not stabilized.B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCLibs-TrackedLibs issues that are tracked on the team's project board.Libs issues that are tracked on the team's project board.T-langRelevant to the language teamRelevant to the language teamT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Description
Feature gate: #![feature(try_trait)]
This is a tracking issue for the Try
trait from rust-lang/rfcs#1859.
Split off from #31436 for clarity (per #42275 (comment))
Public API
pub mod core {
pub mod result {
impl<T, E> ops::Try for Result<T, E> {
type Ok = T;
type Error = E;
fn into_result(self) -> Self {}
fn from_ok(v: T) -> Self {}
fn from_error(v: E) -> Self {}
}
}
pub mod option {
#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
pub struct NoneError;
impl<T> ops::Try for Option<T> {
type Ok = T;
type Error = NoneError;
fn into_result(self) -> Result<T, NoneError> {}
fn from_ok(v: T) -> Self {}
fn from_error(_: NoneError) -> Self {}
}
}
pub mod ops {
mod r#try {
pub trait Try {
type Ok;
type Error;
fn into_result(self) -> Result<Self::Ok, Self::Error>;
fn from_error(v: Self::Error) -> Self;
fn from_ok(v: Self::Ok) -> Self;
}
}
pub use self::r#try::Try;
}
}
Steps / History
-
Stabilizing this will allow people to implementIterator::try_fold
-
As part of stabilizing, re-open PR Document implementingtry_fold
for iterators for internal iteration #62606 to document implementing try_fold for iterators -
Ensure that the default implementations of other things have the desired long-term DAG, since changing them is essentially impossible later. (Specifically, it would be nice to havefold
be implemented in terms oftry_fold
, so that both don't need to be overridden.) - Moved these to the
try_trait_v2
tracking issue
-
-
Deprecate and remove these in favour of the new versions.
Unresolved Questions
These resulted in a new rust-lang/rfcs#3058, tracked in #84277
- Open design questions around the shape of the
Try
trait-
TryContinue
API: Tracking issue forops::Try
(try_trait
feature) #42327 (comment) and Tracking issue forops::Try
(try_trait
feature) #42327 (comment) - Support trace capturing: Tracking issue for
ops::Try
(try_trait
feature) #42327 (comment)
-
- Usability concerns with the current trait
kevincox, aljce, ErichDonGubler, aymericbeaumet, drrlvn and 70 moreluojia65, spacejam, hugecheese, rossproduct, raftario and 6 moreKrantz-XRF and ohsayan
Metadata
Metadata
Assignees
Labels
A-error-handlingArea: Error handlingArea: Error handlingB-RFC-implementedBlocker: Approved by a merged RFC and implemented but not stabilized.Blocker: Approved by a merged RFC and implemented but not stabilized.B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCLibs-TrackedLibs issues that are tracked on the team's project board.Libs issues that are tracked on the team's project board.T-langRelevant to the language teamRelevant to the language teamT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.