Expand description
fieldwork generates field accessor methods for structs and enums via a
derive macro.
Add #[derive(Fieldwork)] to a struct or enum, then
declare which methods to generate with #[fieldwork(...)] on the item and
refine individual fields with #[field(...)].
§Methods
| Module | Generated method | Description |
|---|---|---|
get | field_name() | Borrow or copy a field |
set | set_field_name() | Mutating setter, returns &mut Self by default |
get_mut | field_name_mut() | Mutably borrow a field |
with | with_field_name() | Owned chainable setter |
without | without_field_name() | Set bool to false or Option to None |
take | take_field_name() | Take the value out of an Option field |
into_field | into_field_name() | Consume self, returning an owned field value |
§Enum support
All method types work on enums. Whether a field appears in all variants or
only some determines the return type and whether setters are generated. See
enums for the full/partial coverage concept and examples.
§Configuration
Fieldwork has four levels of configuration that cascade from broadest to most specific.
See configuration for a full explanation.
Options shared across setter methods (into, option_set_some) are documented at the
top level since they apply equally to set and with.
Modules§
- configuration
- Configuration
- enums
- Enum support
- get
get— immutable field accessors- get_mut
get_mut— mutable field accessors- into
into— acceptimpl Into<T>in setters- into_
field into_field— consuming field accessors- option_
set_ some option_set_some— acceptTinstead ofOption<T>in setters- set
set— mutating field setters- take
take— take the value out of anOptionfield- with
with— owned chainable setters- without
without— negative owned setters