Skip to main content

Crate fieldwork

Crate fieldwork 

Source
Expand description

fieldwork generates field accessor methods for structs via a derive macro.

Add #[derive(Fieldwork)] to a struct, then declare which methods to generate with #[fieldwork(...)] on the struct and refine individual fields with #[field(...)].

§Methods

ModuleGenerated methodDescription
getfield_name()Borrow or copy a field
setset_field_name()Mutating setter, returns &mut Self by default
get_mutfield_name_mut()Mutably borrow a field
withwith_field_name()Owned chainable setter
withoutwithout_field_name()Set bool to false or Option to None
taketake_field_name()Take the value out of an Option field
into_fieldinto_field_name()Consume self, returning an owned field value

§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
get
get — immutable field accessors
get_mut
get_mut — mutable field accessors
into
into — accept impl Into<T> in setters
into_field
into_field — consuming field accessors
option_set_some
option_set_some — accept T instead of Option<T> in setters
set
set — mutating field setters
take
take — take the value out of an Option field
with
with — owned chainable setters
without
without — negative owned setters

Derive Macros§

Fieldwork
Derive field accessor methods for a struct. See fieldwork for full documentation.