Derive on struct fields

Does anyone know if its possible to derive or implement a trait on a struct field?
I have this struct and I would like to implement Default on it. You can derive Default if all of the structs fields implement default. So that's what prompted my question.

#[derive(Clone, Copy)]
struct Id {
string: [u8; 100] // array

No, you cannot derive or implement traits for struct fields.

You also cannot override the Default derivation for individual fields.

You will need to either implement Default for Id by hand or you can look at using the smart-default crate.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.