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

Derive FromRefSelf and FromRefMutSelf #224

Open
ModProg opened this issue Nov 16, 2022 · 1 comment
Open

Derive FromRefSelf and FromRefMutSelf #224

ModProg opened this issue Nov 16, 2022 · 1 comment

Comments

@ModProg
Copy link
Contributor

ModProg commented Nov 16, 2022

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()
    }
}
@tyranron
Copy link
Collaborator

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

@JelteF JelteF added this to the 1.1.0 milestone Nov 16, 2022
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

3 participants