[][src]Crate rvs_derive

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:

#[derive(ValueStruct)]
struct UserId(String);

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::String it generates additional instance for From<&str>
  • for scalar types value() the result type isn't a reference, for others it is.

Derive Macros

ValueStruct