Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AsMut transparent #352

Open
ModProg opened this issue Apr 24, 2024 · 1 comment
Open

AsMut transparent #352

ModProg opened this issue Apr 24, 2024 · 1 comment

Comments

@ModProg
Copy link
Contributor

ModProg commented Apr 24, 2024

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.

@JelteF
Copy link
Owner

JelteF commented Jul 2, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants