derive-serialize-into 0.1.0

Derive Serialize and Deserialize for wrapper types
Documentation

Documentation Latest version

Derive Serialize, Deserialize for wrapper types

This crate provides several custom derives that make it more convenient to create implementations of serde's Serialize and Deserialize traits for types T that can be converted to or from another type S which already does implement those traits.

One use case is if you have a single-field type like

#[derive(SerializeInto, DeserializeFrom)]
struct Contact {
    email: String,
}

which you want to serialize and deserialize as a string instead of a struct.

Another example is a validated wrapper type like

#[derive(DeserializeTryFrom)]
struct Email(String);

that should never be instantianted with a string that doesn't represent a valid email address. If you implement Email: TryFrom<String> using the try_from crate, such that conversion fails for invalid addresses, the derived Deserialize will also fail if the string is in the wrong format.