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

Deref and DerefMut share attr tags #417

Open
AstrickHarren opened this issue Sep 29, 2024 · 2 comments
Open

Deref and DerefMut share attr tags #417

AstrickHarren opened this issue Sep 29, 2024 · 2 comments

Comments

@AstrickHarren
Copy link

As an example:

/// does not compile because Deref(Mut) targets must be the same type. 
#[derive(Deref, DerefMut)]
pub struct Foo {
    #[deref]
    inner:   String,
    #[deref_mut]
    another: i32, // would work if this is of also of type `String`
}

Therefore, 99% of programs will put #[deref] and #[deref_mut] on the same field. I purpose DerefMut to
operate on #[deref] field as a fallback if there is no #[deref_mut] tag. Like this:

/// Both derives from #[deref] field (inner)
#[derive(Deref, DerefMut)]
pub struct Foo {
    #[deref]
    inner:   String,
    another: i32, 
}
@AstrickHarren AstrickHarren changed the title why does Deref and DerefMut has different attr tags Deref and DerefMut share attr tags Sep 29, 2024
@JelteF
Copy link
Owner

JelteF commented Sep 29, 2024

Seems reasonable. Feel free to create a PR for that

@AstrickHarren
Copy link
Author

I'll try to help on the weekend :)

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