#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

30 releases (stable)

1.13.0 Jun 25, 2024
1.11.0 Apr 13, 2024
1.10.0 Feb 10, 2024
1.9.0 Jul 22, 2023
0.1.3 Sep 25, 2015

#35 in Data structures

Download history 2212841/week @ 2024-04-05 2384514/week @ 2024-04-12 2434261/week @ 2024-04-19 2297836/week @ 2024-04-26 2398454/week @ 2024-05-03 2430980/week @ 2024-05-10 2588089/week @ 2024-05-17 2408620/week @ 2024-05-24 2528372/week @ 2024-05-31 2542734/week @ 2024-06-07 2501022/week @ 2024-06-14 2623239/week @ 2024-06-21 2431756/week @ 2024-06-28 2476477/week @ 2024-07-05 2561833/week @ 2024-07-12 2227412/week @ 2024-07-19

10,180,358 downloads per month
Used in 32,197 crates (826 directly)

MIT/Apache

62KB
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

~170KB