rust-derivative
rust-derivative copied to clipboard
Can default values be specified in some shorter way?
In #[derivative(Default(value="123"))] boilerplate is ten times bigger than the value itself.
Maybe it can just be sometihng like #[default("123")]? This way it's only five times bigger.
The short form may be opt-out with cargo features to provide a way of dealing with conflicts with other derives.
All attributes must be on the form #[derivative(…)], but we could do something like #[derivative(Default=123)].
proc_macro_derive(Derivative, attributes(derivative))
Can't there be other, multiple attributes apart from derivative?
All attributes must be on the form #[derivative(…)]
There is no requirement from #[proc_macro_derive] that attributes must be of one form with a specific keyword related to the #[derive]. The question is whether those attributes might conflict with other attributes from other derives.
In smart-default it's just #[default].
I don't want just #[default("123")] because that might conflict with other stuffs. Eg. even serde uses #[serde(default = "foo")].
What if, similar to use foo as bar, you could write this?
#[derive(Derivative)]
#[derivative(Default as bar)]
pub struct Foo {
#[bar("123")]
a: u32,
}
This way it's up to the user to avoid name conflicts and in the same way name conflicts are avoided in other contexts.