rvstruct/
lib.rs

1//! Value Structs derive macros for Rust to support the newtype pattern
2//!
3//! A very simple derive macros to support strong type system and
4//! the new type pattern (https://doc.rust-lang.org/1.0.0/style/features/types/newtype.html).
5//!
6//! For example:
7//! ```
8//! use rvstruct::ValueStruct;
9//!
10//! #[derive(ValueStruct)]
11//! struct UserId(String);
12//!
13//! let uid : UserId = "my-uid".into();
14//! ```
15//!
16//! `ValueStruct` generates for you:
17//!  - `std::convert::From<>` instances automatically to help you to create your structs.
18//!  - `ValueStruct::value()` function to access your field directly without using .0.
19//!
20//! There are different behaviour for different field types:
21//! - for `std::string::String` it generates additional instance for `From<&str>`
22//!
23
24pub use rvs_derive::*;
25
26pub trait ValueStruct {
27    type ValueType;
28
29    fn value(&self) -> &Self::ValueType;
30
31    fn into_value(self) -> Self::ValueType;
32}