#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

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

#54 in Data structures

Download history 2738281/week @ 2024-11-25 3257835/week @ 2024-12-02 3501870/week @ 2024-12-09 3208550/week @ 2024-12-16 1630721/week @ 2024-12-23 1780792/week @ 2024-12-30 3046806/week @ 2025-01-06 3235155/week @ 2025-01-13 3133637/week @ 2025-01-20 3582721/week @ 2025-01-27 3615978/week @ 2025-02-03 3583328/week @ 2025-02-10 3668722/week @ 2025-02-17 3950692/week @ 2025-02-24 4317811/week @ 2025-03-03 4256394/week @ 2025-03-10

16,387,960 downloads per month
Used in 40,349 crates (1,016 directly)

MIT/Apache

61KB
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:

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

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

Dependencies

~155KB