Skip to main content

WritableKeypaths

Derive Macro WritableKeypaths 

Source
#[derive(WritableKeypaths)]
Expand description

Derives only writable keypath methods for struct fields.

This macro is a convenience wrapper that generates only writable keypaths, equivalent to using #[derive(Kp)] with #[Writable] on the struct.

§Generated Methods

For each field field_name, generates:

  • field_name_w() - Returns a WritableKeyPath<Struct, FieldType> for non-optional fields
  • field_name_fw() - Returns a WritableOptionalKeyPath<Struct, InnerType> for optional/container fields
  • field_name_fw_at(index) - Returns a WritableOptionalKeyPath for indexed mutable access

§Examples

use keypaths_proc::WritableKeypaths;

#[derive(WritableKeypaths)]
struct Counter {
    value: u32,
    history: Vec<u32>,
}

// Usage:
let mut counter = Counter { value: 0, history: vec![] };
let value_path = Counter::value_w();
*value_path.get_mut(&mut counter) += 1;