#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

#65 in Rust patterns

Download history 4907171/week @ 2025-09-27 4925205/week @ 2025-10-04 4958008/week @ 2025-10-11 5262298/week @ 2025-10-18 5557531/week @ 2025-10-25 5509018/week @ 2025-11-01 5419951/week @ 2025-11-08 5741393/week @ 2025-11-15 5217871/week @ 2025-11-22 5881816/week @ 2025-11-29 6589741/week @ 2025-12-06 6833401/week @ 2025-12-13 4031486/week @ 2025-12-20 3567600/week @ 2025-12-27 6535949/week @ 2026-01-03 6260128/week @ 2026-01-10

21,480,862 downloads per month
Used in 56,459 crates (1,260 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