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

no-std either

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

27 releases (stable)

1.10.0 Feb 10, 2024
1.9.0 Jul 22, 2023
1.8.1 Jan 26, 2023
1.8.0 Aug 17, 2022
0.1.3 Sep 25, 2015

#37 in Data structures

Download history 1938642/week @ 2023-11-27 1924550/week @ 2023-12-04 2020620/week @ 2023-12-11 1694945/week @ 2023-12-18 1031117/week @ 2023-12-25 1588801/week @ 2024-01-01 1944212/week @ 2024-01-08 1974060/week @ 2024-01-15 1966647/week @ 2024-01-22 2095081/week @ 2024-01-29 2121886/week @ 2024-02-05 2299724/week @ 2024-02-12 2311757/week @ 2024-02-19 2405184/week @ 2024-02-26 2326406/week @ 2024-03-04 896130/week @ 2024-03-11

8,091,278 downloads per month
Used in 28,611 crates (745 directly)

MIT/Apache

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

~180KB