Crate derived_deref

Source
Expand description

A crate for deriving the Deref and DerefMut traits from the standard library onto structs with at least one field. Fields with references are passed directly.

§Examples

use derived_deref::{Deref, DerefMut};

#[derive(Deref, DerefMut)]
struct StringWithCount {
    // Annotation of `#[target]` is required when there are two+ fields.
    #[target] inner: String,
    count: usize,
}
 

// When there is only one field, annotation is optional instead.

#[derive(Deref, DerefMut)]
struct StringWrapper(String);

#[derive(Deref, DerefMut)]
struct CountWrapper(#[target] usize);

Derive Macros§

Deref
Derives the Deref trait, passing the field directly if a reference type.
DerefMut
Derives the DerefMut trait, passing the field directly if a reference type. This will fail to compile if the chosen field is an immutable reference type.