derive_more icon indicating copy to clipboard operation
derive_more copied to clipboard

Derive FromRefSelf and FromRefMutSelf

Open ModProg opened this issue 3 years ago • 1 comments
trafficstars

This is something the standard library does, for example for String: https://doc.rust-lang.org/src/alloc/string.rs.html#2645

Basically, the derive would just wrap a Clone call. This allows functions taking Into<T> to also take &T.

impl From<&mut Self> for Something {
    fn from(this: &mut Self) -> Self {
        this.clone()
    }
}

impl From<&Self> for Something {
    fn from(this: &Self) -> Self {
        this.clone()
    }
}

ModProg avatar Nov 16 '22 09:11 ModProg

I'd like to see this rather as derive(From) customization with attributes, rather than separate macros.

tyranron avatar Nov 16 '22 10:11 tyranron