Skip to main content

Crate reflica

Crate reflica 

Source
Expand description

§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!");

Attribute Macros§

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