It seems relevant and has not been mentioned yet, the crate derivative does a good job of implementing some standard traits automatically with ignoring some fields.
I wish Rust's attributes were namespaced! Fortunately serde self-namespaces in a way, it's #[serde(skip_serializing)] so it's less likely to conflict with some other macro or custom derive, but I wish we had more mechanisms to ensure that attribute macros will compose
I mean, I can see #[skip] possibly conflicting with something else, as well as the already stabilized #[default]
Rust should at least have a way to make an attribute visible only to a specific macro, something like #[macro_attr(myattrmacro, skip)] which makes #[skip] visible to #[myattrmacro], like this:
#[derive(Ord)]
#[myattrmacro]
pub struct A {
#[macro_attr(myattrmacro, skip)]
something: B,
}
So that #[myattrmacro] sees
pub struct A {
#[skip]
something: B,
}
And #[derive(Ord)] sees
pub struct A {
something: B,
}
2 Likes
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.