Value Structs ("classes") derive macros for Rust
A very simple derive macros to support strong type system and avoid bare types (like String) for domain types using Rust structs with exactly one unnamed field as a immutable value type.
This is similar approach to Haskell's newtype (https://wiki.haskell.org/Newtype) or Scala's AnyVal.
e.g. to declare something like this:
use ValueStruct;
;
let uid : UserId = "my-uid".into;
ValueStruct generates for you:
std::convert::From<>instances automatically to help you to create your structs.- an inline
value()function to access your field directly without using .0.
There are different behaviour for different field types:
- for
std::string::Stringit generates additional instance forFrom<&str> - for scalar types
value()the result type isn't a reference, for others it is.