shared-struct
A procedural macro that transforms a struct into a shared, cheaply-cloneable wrapper with per-field fine-grained locking. Each field gets its own tokio::sync::Mutex, so concurrent access to different fields does not block. The wrapper itself is an Arc — cloning is cheap and all clones share the same data.
Usage
use shared;
What gets generated
;
Field attributes
| Attribute | Storage | Accessor |
|---|---|---|
| (default) | Mutex<T> |
async fn field(&self) -> MutexGuard<T> |
#[raw] |
T (no lock) |
fn field(&self) -> &T |
Clone semantics
clone() is Arc::clone — all clones share the same data.
let ctx = new;
let ctx2 = ctx.clone;
*ctx.name.await = "world".to_string;
assert_eq!; // same Arc
Visibility
Field visibility is preserved on ContextInner and all accessors.
Dependencies
Runtime crate requires tokio with the sync feature.