reflica 0.2.0

Automatically implements Deref / DerefMut / AsRef / AsMut from the given deref / deref_mut
Documentation
  • Coverage
  • 100%
    2 out of 2 items documented1 out of 2 items with examples
  • Size
  • Source code size: 15.42 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 295.09 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 5s Average build duration of successful builds.
  • all releases: 5s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • kimhappy/reflica
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • kimhappy

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