lock_api
Wrappers to create fully-featured Mutex and RwLock types. Compatible with no_std.
This package has a good security score with no known vulnerabilities.
Community Reviews
Rock-solid foundation for custom synchronization primitives
The library is exceptionally lean with zero runtime overhead beyond what your raw lock implementation adds. The RawMutex and RawRwLock traits are well-designed, making it straightforward to wrap platform-specific primitives or implement fairness policies. The type system ensures you can't accidentally create unsound lock types - const_mutex_lock enforces compile-time initialization requirements properly.
No_std compatibility is genuine and complete, making it valuable for embedded work. Documentation could use more real-world examples, but the traits are simple enough that reading parking_lot's implementation serves as excellent reference material. The stable API across versions means zero maintenance burden once integrated.
Best for: Building custom synchronization primitives with specialized behavior while maintaining ergonomic, std-compatible APIs.
Avoid if: You just need standard mutexes - use parking_lot or std::sync directly instead.
Solid foundation for building custom synchronization primitives
The documentation is thorough with clear safety requirements for each trait method. Type safety is excellent - the guard types properly encode lock state at compile time. The no_std compatibility is genuine and well-tested. Day-to-day usage is straightforward once you understand the separation between raw primitives and high-level wrappers.
The main friction point is the learning curve for first-time implementers. The trait methods require careful attention to safety invariants, and debugging incorrect implementations can be challenging. Error messages are standard Rust fare - helpful for type errors but less so when you violate safety contracts. That said, if you're consuming this indirectly through parking_lot, the experience is seamless.
Best for: Library authors building custom synchronization primitives or alternative lock implementations that need consistent high-level APIs.
Avoid if: You just need standard mutexes and rwlocks for application code - use parking_lot or std::sync directly instead.
Solid foundation for building custom synchronization primitives
The documentation is thorough with clear explanations of what each trait method must guarantee. Type hints are first-class, and IDE autocomplete works flawlessly. The separation between raw lock implementations and user-facing types is elegant and allows for great flexibility. However, there's a learning curve understanding when to use ReentrantMutex vs Mutex, and the distinction between lock() and try_lock() semantics in trait implementations.
Error messages are generally clear, though some trait bound errors when implementing custom locks can be cryptic. The no_std support is genuinely useful for embedded work, and the crate integrates well with parking_lot and other ecosystem locks.
Best for: Building custom synchronization primitives or integrating platform-specific locking mechanisms with Rust's ecosystem.
Avoid if: You just need standard mutexes—use std::sync or parking_lot directly instead.
Sign in to write a review
Sign In