An algebraic data type combines product and sum type constructors to represent a defined set of values. Structs behave like product types, while Rust enums provide sum types whose restricted states work well with pattern matching. section 7.3
The two principal forms are:
- Product type: combines properties, so possible states multiply; a u8 field and a boolean field allow 512 combinations. section 7.3
- Sum type: selects among alternatives, so possible states add; Rust enums model these alternatives and support pattern matching. section 7.3
Representing success or failure
A custom enum can make outcomes explicit: Either<T> has Success(T) and Failure(String). Matching on the result forces the caller to distinguish the success path from failure handling.




