#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 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 6536294/week @ 2026-01-03 7444441/week @ 2026-01-10 7467167/week @ 2026-01-17 8016728/week @ 2026-01-24 8311646/week @ 2026-01-31 8960518/week @ 2026-02-07

34,071,970 downloads per month
Used in 59,737 crates (1,287 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

~155KB