Try_v2
Provides a derive macro for Try & optionally Try_ConvertResult for interconversion with
std::result::Result and Try_Iterator for iterating over IntoIterator and collecting from
FromIterator analogous to how Result & Option do this.
See (try_trait_v2) for more details
of the underlying trait.
Requires
- nightly
#![feature(never_type)]#![feature(try_trait_v2)]#![feature(try_trait_v2_residual)]- optionally:
#
Limitations on the annotated type
- must be an
enum - must have at least one generic type
- the first generic type must be the
Outputtype (produced when not short circuiting) - the output variant (does not short-circuit) must be the first variant and store the output type as the only unnamed field
See the full documentation for specifics on the generated code.
Example Usage
use ;
// Basic short circuiting thanks to `#[derive(Try)]`
assert!;
// Conversion from std::result::Result thanks to `#[derive(Try_ConvertResult)]`
assert!;
Stability & MSRV
Given that this crate exposes an experimental API from std it makes use of experimental features which require a nightly toolchain.
In order to use this crate you must enable the features which it exposes:
🔬 Required Experimental Features
#![feature(never_type)]#![feature(try_trait_v2)]#![feature(try_trait_v2_residual)]- optionally:
#
This crate makes use of the following experimental features in addition to those which it directly supports:
🔬 Additional Experimental Features
##This list includes any unstable features used by direct & transitive dependencies (currently, none).
You do not need to enable these in your own code, the list is for information only.
Stability guarantees
We run automated tests every month to ensure no fundamental changes affect this crate and test every PR against the current nightly, as well as the current equivalent beta & stable. If you find an issue before we do, please raise an issue on github.
MSRV
For those of you working with a pinned nightly (etc.) this crate supports every version of edition 2024 (rust 1.85.1 onwards, released as stable on 2025-03-18). We use autocfg to seamlessly handle features which have been stabilised since then.
Currently untested (may work, may not ...)
whereclauses- storing
Fns in variants