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

Feature: Support skip on Clone derives #104

Open
overdrivenpotato opened this issue Jan 21, 2025 · 3 comments · May be fixed by #105
Open

Feature: Support skip on Clone derives #104

overdrivenpotato opened this issue Jan 21, 2025 · 3 comments · May be fixed by #105
Assignees

Comments

@overdrivenpotato
Copy link

Sometimes, it's useful to derive Clone for types with fields that cannot be cloned, and need to be re-initialized:

#[derive_where(Clone, Debug)]
struct Foo {
    // Defaults to `Option::<TcpStream>::default()` on clone
    #[derive_where(skip(Clone))]
    connection: Option<TcpStream>,
    s: String,
    #[derive_where(skip(Debug))]
    i: i32,
}

Alternatively maybe #[derive_where(default(Clone))] makes more sense here.

@ModProg
Copy link
Owner

ModProg commented Jan 21, 2025

I guess using default for something like this wouldn't be too uncommon, looking at std functionality like mem::take.

@overdrivenpotato
Copy link
Author

serde's derive macro also has a similar feature #[serde(default)]

@ModProg ModProg self-assigned this Jan 30, 2025
@ModProg
Copy link
Owner

ModProg commented Jan 30, 2025

@daxpedda should this be part of a general skip (would be a breaking change) and it would pose a strange problem in combination with Copy.

Should this be allowed if the type also derives Copy? I guess we need to prevent this if we don't want scenarios where a copy and a clone are !=.

@ModProg ModProg linked a pull request Jan 30, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants