Expand description
§Sync keypath module (sync_kp)
This module provides SyncKp for safely navigating through locked/synchronized data structures.
§Naming convention (aligned with crate::Kp and crate::async_lock)
then– chain with a plain crate::Kpthen_sync– chain with another SyncKp for multi-level lock access
§SHALLOW CLONING GUARANTEE & NO UNNECESSARY CLONES
IMPORTANT: All cloning operations in this module are SHALLOW (reference-counted) clones:
-
SyncKpderivesClone: Clones function pointers and PhantomData onlyprevandnextfields contain function pointers (cheap to copy)midfield is typically justPhantomData<T>(zero-sized, zero-cost)- No heap allocations or deep data copies
-
NO
Lock: Clonerequired for most operations:lock_writetakes&Lock(not&mut Lock) due to interior mutability- For
Arc<Mutex<T>>: No cloning needed, we just use&Arc<...> - The actual data
Tinside is NEVER cloned during lock operations - This eliminates unnecessary Arc reference count increments
-
L: Clonebound (e.g.,ArcMutexAccess<T>):- Only clones
PhantomData<T>which is zero-sized - Compiled away completely - zero runtime cost
- Only clones
§Performance Characteristics
SyncKp::clone(): O(1) - copies a few pointersArcMutexAccess::clone(): O(1) - no-op (zero-sized type)- Lock operations: No Arc cloning needed - direct reference use
- Total: All operations are constant-time with no deep copying
§Memory Safety
The design is safe because:
- Locks provide interior mutability (no
&mutneeded for write operations) Arcprovides thread-safe reference countingMutexensures exclusive access when needed- No dangling pointers or use-after-free possible
- Rust’s ownership system enforces correctness
Structs§
- ArcMutex
Access - Lock access implementation for Arc<Mutex
> - ArcRw
Lock Access - Lock access implementation for Arc<RwLock
> - Composed
Sync KeyPath - Composes two
crate::async_lock::SyncKeyPathLikesteps (used byKpThenSyncKp::then/KpThenSyncKp::then_sync). - KpThen
Sync Kp - Keypath that chains a crate::Kp with a SyncKp. Use [crate::Kp::then_sync] to create.
- RcRef
Cell Access - Lock access implementation for Rc<RefCell
> - StdMutex
Access - Lock access implementation for std::sync::Mutex
(without Arc wrapper) - StdRw
Lock Access - Lock access implementation for std::sync::RwLock
(without Arc wrapper) - SyncKp
- A keypath that handles locked values (e.g., Arc<Mutex
>)
Traits§
- Lock
Access - Trait for types that can provide lock/unlock behavior Converts from a Lock type to Inner or InnerMut value
Type Aliases§
- Sync
KpArc Mutex For - Type alias for SyncKp over Arc<std::sync::Mutex
>. Use with derive macro’s _lock()methods. - Sync
KpArc Mutex Option For - Type alias for SyncKp over Arc<std::sync::Mutex<Option
>>; value is T (extract from Option). - Sync
KpArc RwLock For - Type alias for SyncKp over Arc<std::sync::RwLock
>. Use with derive macro’s _lock()methods. - Sync
KpArc RwLock Option For - Type alias for SyncKp over Arc<std::sync::RwLock<Option
>>; value is T (extract from Option). - Sync
KpType - Type alias for common SyncKp usage with Arc<Mutex
>