Crates.io | derive-deref-rs |
lib.rs | derive-deref-rs |
version | 0.1.1 |
source | src |
created_at | 2022-04-10 23:37:16.078066 |
updated_at | 2022-04-10 23:42:20.279716 |
description | derive-deref-rs is a derive macro library used to easily defined the Derive and DrerfMut trait of the core library. |
homepage | |
repository | https://github.com/MathieuGravel/derive-deref-rs |
max_upload_size | |
id | 565290 |
size | 14,438 |
Crate derive-deref-rs
is a macro library used to easily defined the Derive and DrerfMut trait of the core library.
#[derive(Deref)]
#[derive(Deref)] struct MyStruct { a: String }
this will implement the Deref and DerefMut trait with the field a.
#[derive(Deref)] struct MyStruct(String);
This will also work since it's have only one field.
struct MyStruct { #[deref] a: String, b: String }
When a structure has multiple field, we need to tell which field will be used to dereference the structure. To do that, simply add
#[deref]
on the field you want to use. You can only use this attribute once, otherwise a compile error will occur.
#[deref]
attribute.