newtypes 0.1.0

Macros that ease the implementation of the Newtype pattern
Documentation
use newtypes::*;
use serde::{Deserialize, Serialize};

newtype!(UserId, u32; Serialize, Deserialize);
newtype_from!(UserId, u32);

newtype_unit!(Weight, f32; Serialize, Deserialize);
newtype_from!(Weight, f32);

#[derive(Debug, Serialize, Deserialize, PartialEq)]
struct UserData {
    uid: UserId,
    uname: String,
    weight: Weight,
}

#[test]
fn test_extra_derive() {
    let str_user_data = r#"
    {
        "uid": 42,
        "uname": "john",
        "weight": 77.75
    }
    "#;

    let user_data: UserData = serde_json::from_str(str_user_data).unwrap();

    assert_eq!(
        UserData {
            uid: UserId(42),
            uname: String::from("john"),
            weight: Weight(77.75),
        },
        user_data
    );
}