derive-where
derive-where copied to clipboard
Feature: Support `skip` on `Clone` derives
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.
I guess using default for something like this wouldn't be too uncommon, looking at std functionality like mem::take.
serde's derive macro also has a similar feature #[serde(default)]
@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 !=.