Using enums to represent state in Rust
corrode.dev
Using enums to represent state in Rust
1–10 of 89 posts
Re: Using enums to represent state in Rust
#2Re: Using enums to represent state in Rust
#3Re: Using enums to represent state in Rust
#4Re: Using enums to represent state in Rust
#5Re: Using enums to represent state in Rust
#6I kind of consider algebraic data types (the combination of this style of enum (sum types) and structs (product types)) paired with pattern matching as the core feature set that any modern language must support. It makes for really simple, easy to follow code that’s much less error prone than the alternatives.
Re: Using enums to represent state in Rust
#7I kind of consider algebraic data types (the combination of this style of enum (sum types) and structs (product types)) paired with pattern matching as the core feature set that any modern language must support. It makes for really simple, easy to follow code that’s much less error prone than the alternatives.
Re: Using enums to represent state in Rust
#8I kind of consider algebraic data types (the combination of this style of enum (sum types) and structs (product types)) paired with pattern matching as the core feature set that any modern language must support. It makes for really simple, easy to follow code that’s much less error prone than the alternatives.
Combine it with switches and you get compiler guarantees that every state is explicitly handled, and if you are in a particular state you always have the relevant child objects.
I remember being shocked dart lacked this functionality when I tried out flutter.
Re: Using enums to represent state in Rust
#9I kind of consider algebraic data types (the combination of this style of enum (sum types) and structs (product types)) paired with pattern matching as the core feature set that any modern language must support. It makes for really simple, easy to follow code that’s much less error prone than the alternatives.
I joke to myself that I program with "struct and enum-oriented programming". I got it from Rust, but apply it to Python too. (Python enums aren't as ergonomic, and they can't wrap values, but they're a start)
They aren't as ergonomic or type-safe, and rather surprisingly the match statement is not an expression in Python's grammar, but regardless of its problems the match statement is very powerful, even more so than static equivalents.
Re: Using enums to represent state in Rust
#10Very powerful tool. I wish Go had (real) enums.
https://github.com/containerd/runwasi/blob/ba5ab5ada5a401762...