#deref-mut #as-mut #automatic #as-ref

macro reflica

Automatically implements Deref / DerefMut / AsRef / AsMut from the given deref / deref_mut

2 unstable releases

0.2.0 Feb 26, 2026
0.1.0 Feb 26, 2026

#2529 in Procedural macros

Download history 2/week @ 2026-02-23 31/week @ 2026-03-02 199/week @ 2026-03-09 478/week @ 2026-03-16 285/week @ 2026-03-23 298/week @ 2026-03-30

1,263 downloads per month
Used in deadlock

MIT license

8KB
152 lines

reflica

Automatically implements Deref / DerefMut / AsRef / AsMut from the given deref / deref_mut.

crates.io docs.rs License

Example

struct Wrapper {
    value: String,
}

#[reflica::reflica]
impl Wrapper {
    type Target = String;

    pub fn new(value: String) -> Self {
        Self { value }
    }

    fn deref(&self) -> &Self::Target {
        &self.value
    }

    fn deref_mut(&mut self) -> &mut Self::Target {
        &mut self.value
    }
}

let mut wrapper = Wrapper::new("Hello".into());

let as_ref: &str = wrapper.as_ref();
assert_eq!(as_ref, "Hello");

let as_mut: &mut String = wrapper.as_mut();
as_mut.push_str(", world!");
assert_eq!(*as_mut, "Hello, world!");

Dependencies

~115–485KB
~12K SLoC