#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

#55 in Rust patterns

Download history 3255550/week @ 2025-01-11 3090839/week @ 2025-01-18 3493474/week @ 2025-01-25 3651232/week @ 2025-02-01 3643621/week @ 2025-02-08 3602484/week @ 2025-02-15 3946714/week @ 2025-02-22 4274816/week @ 2025-03-01 4455343/week @ 2025-03-08 4710675/week @ 2025-03-15 4861367/week @ 2025-03-22 4401194/week @ 2025-03-29 4686901/week @ 2025-04-05 4322157/week @ 2025-04-12 4230801/week @ 2025-04-19 4153229/week @ 2025-04-26

18,141,607 downloads per month
Used in 42,724 crates (1,066 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

~150KB