#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

#42 in Data structures

Download history 2042872/week @ 2024-01-16 1978513/week @ 2024-01-23 2088641/week @ 2024-01-30 2166613/week @ 2024-02-06 2248197/week @ 2024-02-13 2385104/week @ 2024-02-20 2391727/week @ 2024-02-27 2300680/week @ 2024-03-05 2285876/week @ 2024-03-12 2317885/week @ 2024-03-19 2166361/week @ 2024-03-26 2335001/week @ 2024-04-02 2251547/week @ 2024-04-09 2392495/week @ 2024-04-16 2402650/week @ 2024-04-23 1957949/week @ 2024-04-30

9,377,417 downloads per month
Used in 29,726 crates (771 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

~185KB