#field #deref #deref-mut #traits #deriving #reference #derived

macro derived-deref

Crate for deriving the Deref and DerefMut traits

5 releases (stable)

2.1.0 Aug 15, 2023
2.0.1 Aug 15, 2023
1.0.0 Jul 7, 2023
0.1.0 Jul 7, 2023

#9 in #deref-mut

Download history 1/week @ 2024-06-30 47/week @ 2024-07-07 77/week @ 2024-07-14 48/week @ 2024-07-21 58/week @ 2024-07-28 15/week @ 2024-08-04 51/week @ 2024-08-11 95/week @ 2024-08-18 68/week @ 2024-08-25 48/week @ 2024-09-01 44/week @ 2024-09-08 16/week @ 2024-09-15 72/week @ 2024-09-22 16/week @ 2024-09-29 28/week @ 2024-10-06 31/week @ 2024-10-13

149 downloads per month
Used in 2 crates

MIT/Apache

10KB
112 lines

derived-deref

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);

lib.rs:

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);

Dependencies

~235–680KB
~16K SLoC