Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
a5ca2d8
move macro to try_v2_derive
MusicalNinjaDad Jun 1, 2026
27b07a0
pub reexport from new try_v2 crate
MusicalNinjaDad Jun 1, 2026
3cb7934
fix doc link
MusicalNinjaDad Jun 1, 2026
ce2855e
Transform::transpose
MusicalNinjaDad Jun 1, 2026
9e8b7f9
Transform::flatten
MusicalNinjaDad Jun 1, 2026
4a51667
widen transpose bounds to better leverage interconversion
MusicalNinjaDad Jun 1, 2026
67c61fb
not re ambiguity
MusicalNinjaDad Jun 1, 2026
cb7fac8
inspect
MusicalNinjaDad Jun 1, 2026
c0130c0
map
MusicalNinjaDad Jun 1, 2026
6295589
map_or
MusicalNinjaDad Jun 1, 2026
1d975b8
test map_or None
MusicalNinjaDad Jun 1, 2026
e04fe38
map_or_else
MusicalNinjaDad Jun 1, 2026
3fe14b1
ambiguous zip
MusicalNinjaDad Jun 1, 2026
94e698e
unambiguous zip
MusicalNinjaDad Jun 1, 2026
866e468
unamabiguous map
MusicalNinjaDad Jun 2, 2026
3595da4
longhand BART, FOOT as helper
MusicalNinjaDad Jun 2, 2026
ca08868
infer option<unknown>
MusicalNinjaDad Jun 2, 2026
ab33158
unambiguous transpose
MusicalNinjaDad Jun 2, 2026
b7c72a3
remove BART & FOOT
MusicalNinjaDad Jun 2, 2026
c22a37a
add V for readability
MusicalNinjaDad Jun 2, 2026
e1a09e9
comments to help future me
MusicalNinjaDad Jun 2, 2026
e3313b9
Document specifics of zip
MusicalNinjaDad Jun 2, 2026
6ef957a
zip_with
MusicalNinjaDad Jun 2, 2026
f486d84
output
MusicalNinjaDad Jun 2, 2026
58deacd
trait doc
MusicalNinjaDad Jun 2, 2026
c0fb713
workspace resolver for 2024 edition
MusicalNinjaDad Jun 2, 2026
64ce39c
doc formatting
MusicalNinjaDad Jun 2, 2026
f84f5cc
standardised generic params
MusicalNinjaDad Jun 2, 2026
e7b38f8
consistently use `V` for other TryType
MusicalNinjaDad Jun 2, 2026
4d0e041
consistently use U & V
MusicalNinjaDad Jun 2, 2026
5a9db68
Use Y for other TryType
MusicalNinjaDad Jun 2, 2026
4ae6cdf
remove unnecessary `U`s
MusicalNinjaDad Jun 2, 2026
5317de0
ordering where clauses for readbility
MusicalNinjaDad Jun 2, 2026
d9ada95
update description for crates.io
MusicalNinjaDad Jun 2, 2026
7ec0475
update changelog & readme
MusicalNinjaDad Jun 2, 2026
9d2a0ea
remove Try_Methods
MusicalNinjaDad Jun 2, 2026
2cc27d5
run msrv check on each crate in CI
MusicalNinjaDad Jun 2, 2026
2a4428a
typo
MusicalNinjaDad Jun 2, 2026
3943e8b
use API Key to publish new crate
MusicalNinjaDad Jun 2, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/rust-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: rust-lang/crates-io-auth-action@bbd81622f20ce9e2dd9622e3218b975523e45bbe #v1.0.4
id: auth
# - uses: rust-lang/crates-io-auth-action@bbd81622f20ce9e2dd9622e3218b975523e45bbe #v1.0.4
# id: auth
- name: Publish
env:
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
# CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
run:
cargo publish
7 changes: 7 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ jobs:
if: needs.skip_check.outputs.should_skip != 'true'

runs-on: ubuntu-latest
strategy:
matrix:
crate: ["try_v2", "try_v2_derive"]

defaults:
run:
working-directory: crates/${{ matrix.crate }}

env:
RUSTC_BOOTSTRAP: 1
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog try_v2

## [v0.5.0]

### New features

- Add `trait Transform` (Forces move of derive macros to own crate & re-export)

### Breaking changes

- Removed derive `Try_Methods` in favour of trait-based implementation

## [v0.4.2]

### Bugfixes
Expand Down
37 changes: 4 additions & 33 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,36 +1,7 @@
[package]
name = "try_v2"
version = "0.4.2"
edition = "2024"
readme = "README.md"
description = "Provides a derive macro for `Try` ([try_trait_v2](https://rust-lang.github.io/rfcs/3058-try-trait-v2.html))"
authors = ["Mike Foster <https://github.com/MusicalNinjaDad>"]
keywords = ["derive", "Try", "try_trait_v2"]
homepage = "https://github.com/MusicalNinjaDad/try_v2"
repository = "https://github.com/MusicalNinjaDad/try_v2"
categories = ["development-tools"]
license = "MIT"
rust-version = "1.85.1"
exclude = [".github", ".devcontainer"]

[lib]
proc-macro = true

[dependencies]
syn = {version = "2.0.117", features = ["full","extra-traits"]}
proc-macro2 = "1.0.106"
proc_macro2_diagnostic = "0.3.0"
quote = "1.0.45"

[dev-dependencies]
log = "0.4.29"
trybuild = "1.0.116"

[build-dependencies]
autocfg = "1.5.1"

[workspace]
members = ["tests/compilation"]
edition = "2024"
resolver = "3"
members = ["crates/*"]

[workspace.dependencies]
try_v2 = { path = "."}
try_v2_derive = { path = "crates/try_v2_derive", version = "0.5.0" }
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# 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](https://rust-lang.github.io/rfcs/3058-try-trait-v2.html)) for more details
of the underlying trait.
Provides:

- a derive macro for `Try`
- traits with standard methods to make TryTypes usable (e.g. `trait Transform` provides `.map()`)
- derive `Try_ConvertResult` for interconversion with `std::result::Result`
- derive `Try_Iterator` for iterating over `IntoIterator` and collecting from `FromIterator` analogous to how `Result` & `Option` do this.

See ([try_trait_v2](https://rust-lang.github.io/rfcs/3058-try-trait-v2.html)) for more details of the underlying trait.

## Requires

Expand Down
23 changes: 23 additions & 0 deletions crates/try_v2/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "try_v2"
version = "0.5.0"
edition = "2024"
readme = "README.md"
description = "Provides a derive macro & helper traits for `Try`"
authors = ["Mike Foster <https://github.com/MusicalNinjaDad>"]
keywords = ["derive", "Try", "try_trait_v2"]
homepage = "https://github.com/MusicalNinjaDad/try_v2"
repository = "https://github.com/MusicalNinjaDad/try_v2"
categories = ["development-tools"]
license = "MIT"
rust-version = "1.85.1"
exclude = [".github", ".devcontainer"]

[lib]

[dependencies]
try_v2_derive = { workspace = true }

[dev-dependencies]

[build-dependencies]
123 changes: 123 additions & 0 deletions crates/try_v2/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#![feature(try_trait_v2)]
#![feature(try_trait_v2_residual)]
#![cfg_attr(test, feature(option_zip))]

//! 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` analog to how `Result` & `Option` do this.
//! See ([try_trait_v2](https://rust-lang.github.io/rfcs/3058-try-trait-v2.html)) for more details
//! of the underlying trait.
//!
//! ## Requires
//!
//! - nightly
//! - `#![feature(never_type)]`
//! - `#![feature(try_trait_v2)]`
//! - `#![feature(try_trait_v2_residual)]`
//! - optionally: `#![feature(iterator_try_collect)]` (if using Try_Iterator)
//!
//! ## Limitations on the annotated type
//!
//! - must be an `enum`
//! - must have _at least one_ generic type
//! - the _first_ generic type must be the `Output` type (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
//! - no other variant can store the Output type (TODO #72 add a nice error message)
//!
//! See the individual documentation for [Try], [Try_ConvertResult] and [Try_Iterator] for specifics
//! on the generated code.
//!
//! ## Example Usage
//!
//! ```rust
//! #![feature(never_type)]
//! #![feature(try_trait_v2)]
//! #![feature(try_trait_v2_residual)]
//! use try_v2::{Try, Try_ConvertResult};
//!
//! #[derive(Try, Try_ConvertResult)]
//! enum TestResult<T> {
//! Ok(T),
//! TestsFailed,
//! OtherError(String)
//! }
//!
//! // Basic short-circuiting thanks to `#[derive(Try)]`
//! fn run_tests() -> TestResult<()> {
//! TestResult::OtherError("oops!".to_string())?; // <- Function short-circuits here ...
//! TestResult::TestsFailed?;
//! TestResult::Ok(())
//! }
//!
//! assert!(matches!(run_tests(), TestResult::OtherError(msg) if msg == "oops!"));
//!
//!
//! // Conversion from std::result::Result thanks to `#[derive(Try_ConvertResult)]`
//! struct TestFailure {}
//!
//! impl<T> From<TestFailure> for TestResult<T> {
//! fn from(err: TestFailure) -> Self {
//! TestResult::TestsFailed
//! }
//! }
//!
//! fn run_more_tests() -> TestResult<()> {
//! std::result::Result::Err(TestFailure{})?; // <- Function short-circuits here & converts to a TestResult...
//! TestResult::Ok(())
//! }
//!
//! assert!(matches!(run_more_tests(), TestResult::TestsFailed));
//! ```
//!
//! ## 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)]`](https://github.com/rust-lang/rust/issues/35121)
//! > - [`#![feature(try_trait_v2)]`](https://github.com/rust-lang/rust/issues/84277)
//! > - [`#![feature(try_trait_v2_residual)]`](https://github.com/rust-lang/rust/issues/91285)
//! > - optionally: [`#![feature(iterator_try_collect)]`](https://github.com/rust-lang/rust/issues/94047) (if using [Try_Iterator])
//!
//! This crate makes use of the following experimental features in addition to those which it
//! directly supports:
//!
//! > 🔬 **Additional Experimental Features**
//! >
//! > - [`#![feature(if_let_guard)]`](https://github.com/rust-lang/rust/issues/51114) (stable since 1.95.0)
//! > - [`#![feature(let_chains)]`](https://github.com/rust-lang/rust/issues/139951) (stable since 1.88.0)
//! >
//! > 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](https://github.com/MusicalNinjaDad/try_v2/issues).
//!
//! ### 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](https://crates.io/crates/autocfg/) to seamlessly handle features which have been
//! stabilised since then.
//!
//! ## Currently untested (may work, may not ...):
//!
//! - `where` clauses
//! - storing `Fn`s in variants

#[doc(inline)]
pub use try_v2_derive::*;

mod transform;
#[doc(inline)]
pub use transform::Transform;
Loading
Loading