my code:
fn main() {}
#[derive(Default)]
pub struct Structer {
#[default("ok")]
pub stringy: String,
}
produces this error:
the `#[default]` attribute may only be used on unit enum variants
consider a manual implementation of `Default`rustcClick for full compiler diagnostic
Can u implement this feature?
I think it shouldn't be that hard to impl it. I imagine it would go something like this:
- read the token inserted in the default attribute (in this case
"ok"
) - check the type of the token (in this case
&str
) - check the required type of the field
- append ".to_string() to the token
- use the modified token as field value like this:
fn default(modified_token: &str) -> String {
let default = Structer {
stringy: modified_token.to_string()
};
default
}