derive_more
derive_more copied to clipboard
`derive(AsRef)` should also derive identity impl.
Hi! I believe that:
#[derive(AsRef)]
struct Foo { t:i32 }
should generate identity AsRef
impl in addition to what it generates now:
impl AsRef<Foo> for Foo {
fn as_ref(&self) -> &Self {
self
}
}
Making these instances by hand is cumbersome and they should be generated automatically.
I'm not entirely sure when you would actually want this, but if you can give some useful example I'm definitely open to accepting PRs for this. Should be behind a attribute flag though, e.g. as_ref(Self)
@JelteF @wdanilo I think that this is quite a particular pattern, not enforced neither in std
, nor being useful in a common case.
Now, having the ability to specify #[as_ref(Self)]
should solve the @wdanilo's situation good enough, I think.