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

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

#41 in Data structures

Download history 3931748/week @ 2024-10-10 3559005/week @ 2024-10-17 3012178/week @ 2024-10-24 2797825/week @ 2024-10-31 2988197/week @ 2024-11-07 3376236/week @ 2024-11-14 3238527/week @ 2024-11-21 2815366/week @ 2024-11-28 3535145/week @ 2024-12-05 3265407/week @ 2024-12-12 2269573/week @ 2024-12-19 1565824/week @ 2024-12-26 2581878/week @ 2025-01-02 3265573/week @ 2025-01-09 3082378/week @ 2025-01-16 2807044/week @ 2025-01-23

11,921,643 downloads per month
Used in 38,690 crates (975 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

~160KB