either
The enum `Either` with variants `Left` and `Right` is a general purpose sum type with two cases.
This package has a good security score with no known vulnerabilities.
Community Reviews
Minimal, zero-dependency sum type with excellent security posture
In daily use, `Either` is a workhorse for cases where `Result` or `Option` semantics don't quite fit. The iterator adaptors and trait implementations (Iterator, From, AsRef, etc.) make it ergonomic to work with. Error handling is non-existent because there's nothing that can fail - it's pure data modeling. The type system does all the heavy lifting, and compiler errors guide you correctly.
The crate follows secure-by-default principles perfectly: no configuration, no defaults to get wrong, no panics in normal use. It's impossible to misuse in a way that creates security vulnerabilities. The API is so minimal and well-constrained that input validation happens naturally through Rust's type system.
Best for: Projects requiring a simple sum type without Result/Option semantics, especially where minimizing dependencies is critical.
Avoid if: You need error-handling semantics or context - use Result instead.
Rock-solid foundational type with zero security surface area
In practice, I use `either` primarily for iterator adapters and function return types where I need to express "this or that" without reaching for Result or Option. The type implements all the standard traits you'd expect (Iterator, Debug, Serialize if features are enabled), making it completely transparent in most codebases. Error handling is a non-issue since it's just a container—any validation happens in your code, not the library.
The biggest security win is that this crate follows secure-by-default principles by being impossible to misuse. There are no configuration footguns, no hidden defaults that could leak information, and the API is so straightforward that code review is trivial. It's the kind of dependency you add once and never worry about in security audits.
Best for: Projects requiring a simple sum type with minimal dependencies and no security concerns about the abstraction layer itself.
Avoid if: You need domain-specific validation or error context that Result or custom enums would better express.
Minimal, battle-tested Either type with excellent Iterator integration
The type integrates seamlessly with Rust's ecosystem through comprehensive trait implementations (Debug, Clone, Iterator, etc.). IDE support is excellent with clear type inference and helpful autocomplete. Error messages are standard Rust compiler output, making debugging straightforward. The documentation is concise but covers the essential use cases with practical examples.
One limitation is the minimalist philosophy—there's no `map_left`/`map_right` convenience methods (you use `map_left` via `Either::map_left` or pattern matching). For complex error handling, you might want a Result-like type instead. The crate assumes you understand sum types; newcomers from languages without them may need to read up on the concept first.
Best for: Iterator chains returning heterogeneous types, and domain modeling where Left/Right semantics are clearer than custom enum names.
Avoid if: You need rich error handling semantics—Result or a dedicated error library would be more appropriate.
Sign in to write a review
Sign In