#[derive(Getters)]
{
// Attributes available to this derive:
#[getters]
}
Expand description
Derive accessor or “getter” methods for each field on the struct.
The output types are determined based on the input types, and follow the following rules:
- Primitives (e.g.
i64
) return a copy of themselves. String
fields return&str
.Vec<T>
fields return&[T]
Box<T>
fields return&T
.Option<T>
fields returnOption<&T>
.Rc<T>
andArc<T>
return a clone of themselves.- References and pointers return copies of themselves.
- Fields of any other type
T
return&T
.
Note: You can use #[getters(copy)] to override rule 6 and make other types that implement [
Copy`] also return copies; this can be done either on the struct or on individual fields.