| Crates.io | keypaths-proc |
| lib.rs | keypaths-proc |
| version | 1.9.0 |
| created_at | 2025-12-06 13:24:04.076052+00 |
| updated_at | 2026-01-25 15:05:09.444018+00 |
| description | Proc-macro derive to generate keypath methods using rust-keypaths (static dispatch) |
| homepage | https://github.com/akashsoni01/rust-key-paths |
| repository | https://github.com/akashsoni01/rust-key-paths |
| max_upload_size | |
| id | 1970156 |
| size | 398,124 |
Key paths and case paths provide a safe, composable way to access and modify nested data in Rust. Inspired by Swift’s KeyPath / CasePath system, this feature rich crate lets you work with struct fields and enum variants as first-class values.
The derive macro generates helper methods for Arc<Mutex<T>> and Arc<RwLock<T>> fields:
| Field Type | Generated Methods | Description |
|---|---|---|
Arc<Mutex<T>> (parking_lot default) |
_r(), _w(), _fr_at(kp), _fw_at(kp) |
Chain through parking_lot::Mutex |
Arc<RwLock<T>> (parking_lot default) |
_r(), _w(), _fr_at(kp), _fw_at(kp) |
Chain through parking_lot::RwLock |
Arc<std::sync::Mutex<T>> |
_r(), _w(), _fr_at(kp), _fw_at(kp) |
Chain through std::sync::Mutex |
Arc<std::sync::RwLock<T>> |
_r(), _w(), _fr_at(kp), _fw_at(kp) |
Chain through std::sync::RwLock |
use std::sync::Arc;
use parking_lot::RwLock;
use keypaths_proc::Kp;
#[derive(Kp)]
#[Writable]
struct Container {
// This uses parking_lot::RwLock (default)
data: Arc<RwLock<DataStruct>>,
// This uses std::sync::RwLock (explicit)
std_data: Arc<std::sync::RwLock<DataStruct>>,
}
#[derive(Kp)]
#[Writable]
struct DataStruct {
name: String,
}
fn main() {
let container = Container { /* ... */ };
// Using generated _fr_at() for parking_lot (default)
Container::data_fr_at(DataStruct::name_r())
.get(&container, |value| {
println!("Name: {}", value);
});
// Using generated _fw_at() for parking_lot (default)
Container::data_fw_at(DataStruct::name_w())
.get_mut(&container, |value| {
*value = "New name".to_string();
});
// Using generated _fr_at() for std::sync::RwLock (explicit)
Container::std_data_fr_at(DataStruct::name_r())
.get(&container, |value| {
println!("Name: {}", value);
});
}