derive_more icon indicating copy to clipboard operation
derive_more copied to clipboard

AsMut transparent

Open ModProg opened this issue 1 year ago • 1 comments

I'm not sure what the right syntax is here.

I have a struct containing a &mut String, and want to derive AsMut<String>.

The manual implementation is:

impl AsMut<String> for Struct<'_> {
    fn as_mut(&mut self) -> &mut String {
        self.0
    }
}

But because String does not implement AsMut<String>, both #[as_mut(forward)] and #[as_mut(String)] do not work.

I think to support this a third option, transparent or deref or something along the lines would be needed.

#[derive(AsMut)]
#[as_mut(transparent)]
struct<'a> Struct(&'a mut String);

Would produce the implementation of AsMut from above.

ModProg avatar Apr 24 '24 21:04 ModProg

I think that makes sense, I like transparent best I think.

JelteF avatar Jul 02 '24 11:07 JelteF