Expand description
§Lock Keypath Module
This module provides LockKp 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_lock– chain with another LockKp for multi-level lock access
§SHALLOW CLONING GUARANTEE & NO UNNECESSARY CLONES
IMPORTANT: All cloning operations in this module are SHALLOW (reference-counted) clones:
-
LockKpderivesClone: 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
LockKp::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
> - KpThen
Lock Kp - Keypath that chains a crate::Kp with a LockKp. Use crate::Kp::then_lock to create.
- LockKp
- A keypath that handles locked values (e.g., Arc<Mutex
>) - 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)
Traits§
- Lock
Access - Trait for types that can provide lock/unlock behavior Converts from a Lock type to Inner or InnerMut value
Type Aliases§
- Lock
KpArc Mutex For - Type alias for LockKp over Arc<std::sync::Mutex
>. Use with derive macro’s _lock()methods. - Lock
KpArc RwLock For - Type alias for LockKp over Arc<std::sync::RwLock
>. Use with derive macro’s _lock()methods. - Lock
KpType - Type alias for common LockKp usage with Arc<Mutex
>