Skip to main content

Kp

Derive Macro Kp 

Source
#[derive(Kp)]
Expand description

Derive macro for generating simple keypath methods.

Generates one method per field: StructName::field_name() that returns a Kp. Intelligently handles wrapper types (Option, Vec, Box, Arc, etc.) to generate appropriate keypaths.

§Example

#[derive(Kp)]
struct Person {
    name: String,
    age: i32,
    email: Option<String>,
    addresses: Vec<String>,
}
 
// Generates:
// impl Person {
//     pub fn name() -> Kp<...> { ... }
//     pub fn age() -> Kp<...> { ... }
//     pub fn email() -> Kp<...> { ... } // unwraps Option
//     pub fn addresses() -> Kp<...> { ... } // accesses first element
// }