#enum-variant #data-structures #no-std

no-std either

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

32 releases (stable)

1.15.0 Mar 5, 2025
1.13.0 Jun 25, 2024
1.10.0 Feb 10, 2024
1.9.0 Jul 22, 2023
0.1.3 Sep 25, 2015

#67 in Rust patterns

Download history 4883281/week @ 2025-10-09 5156121/week @ 2025-10-16 5572589/week @ 2025-10-23 5397941/week @ 2025-10-30 5425648/week @ 2025-11-06 5661602/week @ 2025-11-13 5944129/week @ 2025-11-20 5126317/week @ 2025-11-27 6382702/week @ 2025-12-04 6831652/week @ 2025-12-11 5487151/week @ 2025-12-18 3418522/week @ 2025-12-25 5081649/week @ 2026-01-01 7313654/week @ 2026-01-08 7217886/week @ 2026-01-15 8127216/week @ 2026-01-22

28,348,707 downloads per month
Used in 57,920 crates (1,270 directly)

MIT/Apache

61KB
1K SLoC

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

Crate features:

  • "std" Enabled by default. Disable to make the library #![no_std].

  • "serde" Disabled by default. Enable to #[derive(Serialize, Deserialize)] for Either


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.

Dependencies

~160KB