This is a companion repo to service-patterns-go that shows how Rust implements the same functionality.
Rust has first-class enums with compile-time gurantees to their correctnes.
This repo shows two ways to define an enum type that can be converted to/from a String:
src/model/device.rs
- Manually implements type conversion traits from the standard library.src/model/device_strum.rs
- Uses a derive macro from thestrum
crate to generate the conversion traits. This module has only 13 lines of code. Compare that to the pseudo-enum in the Go repo that is capable of representing invalid states, and takes significantly more code.