#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

29 releases (stable)

new 1.12.0 May 16, 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

#43 in Data structures

Download history 1991727/week @ 2024-01-25 2093729/week @ 2024-02-01 2253873/week @ 2024-02-08 2246508/week @ 2024-02-15 2398909/week @ 2024-02-22 2417835/week @ 2024-02-29 2266905/week @ 2024-03-07 2286450/week @ 2024-03-14 2297860/week @ 2024-03-21 2222170/week @ 2024-03-28 2247992/week @ 2024-04-04 2345608/week @ 2024-04-11 2427358/week @ 2024-04-18 2274553/week @ 2024-04-25 2463735/week @ 2024-05-02 1956888/week @ 2024-05-09

9,547,640 downloads per month
Used in 29,965 crates (775 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