#variant #sum #enums #cases #left #right

no-std either

The enum Either with variants Left and Right is a general purpose sum type with two cases

28 releases (stable)

1.11.0 Apr 13, 2024
1.10.0 Feb 10, 2024
1.9.0 Jul 22, 2023
1.8.1 Jan 26, 2023
0.1.3 Sep 25, 2015

#38 in Data structures

Download history 1891585/week @ 2024-01-10 2065192/week @ 2024-01-17 1987598/week @ 2024-01-24 2091937/week @ 2024-01-31 2200151/week @ 2024-02-07 2265347/week @ 2024-02-14 2393110/week @ 2024-02-21 2405128/week @ 2024-02-28 2277752/week @ 2024-03-06 2273984/week @ 2024-03-13 2329009/week @ 2024-03-20 2179131/week @ 2024-03-27 2286716/week @ 2024-04-03 2315787/week @ 2024-04-10 2436581/week @ 2024-04-17 1931969/week @ 2024-04-24

9,403,416 downloads per month
Used in 29,553 crates (768 directly)

MIT/Apache

60KB
1K SLoC

The enum Either with variants Left and Right is a general purpose sum type with two cases.

Either has methods that are similar to Option and Result, and it also implements traits like Iterator.

Includes macros try_left!() and try_right!() to use for short-circuiting logic, similar to how the ? operator is used with Result. Note that Either is general purpose. For describing success or error, use the regular Result.


lib.rs:

The enum Either with variants Left and Right is a general purpose sum type with two cases.

Crate features:

  • "use_std" Enabled by default. Disable to make the library #![no_std].

  • "serde" Disabled by default. Enable to #[derive(Serialize, Deserialize)] for Either

Dependencies

~175KB