Crate deriving_via

source ·
Expand description

§deriving_via

This library provides the DerivingVia derive macro for Newtypes (Single-Field structs). DerivingVia can be used like derive_more.

§Generalised Newtype Deriving

§Example

use deriving_via::DerivingVia;

#[derive(DerivingVia)]
#[deriving(Display)]
struct Newtype(pub i32);

let x = Newtype(0);

println!("{x}");

§Deriving Via

Deriving Via allows deriving from beyond a multiply wrapped hierarchy using transitive type conversion through Deref, Into or From traits.

§Example

use deriving_via::DerivingVia;

#[derive(DerivingVia)]
pub struct Inner(i32);

#[derive(DerivingVia)]
#[deriving(Display(via: i32))]
pub struct Outer(Inner);

let x = Outer(Inner(42));

println!("{x}");

Derive Macros§