Derive Macro Getters

Source
#[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:

  1. Primitives (e.g. i64) return a copy of themselves.
  2. String fields return &str.
  3. Vec<T> fields return &[T]
  4. Box<T> fields return &T.
  5. Option<T> fields return Option<&T>.
  6. Rc<T> and Arc<T> return a clone of themselves.
  7. References and pointers return copies of themselves.
  8. 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.