Surelock
This title could be clearer and more informative.Try out Clickbait Shieldfor free (5 uses left this month).
Surelock is a new Rust crate that provides compile-time deadlock freedom by leveraging Rust's type system. It breaks the circular-wait Coffman condition using two complementary mechanisms: LockSet for same-level atomic multi-lock acquisition (sorted by stable runtime IDs), and Level<N> with LockAfter trait bounds for compile-time enforcement of strictly ascending cross-level lock ordering. A move-only MutexKey token threads through every acquisition, giving the compiler a witness of current lock state without runtime overhead. The design is compared to prior art (happylock and lock_tree), explaining why a total order is chosen over a DAG and why incremental acquisition is supported unlike happylock. The crate is no_std compatible, supports embedded targets including those without native CAS, and provides an escape hatch behind a feature flag for exceptional cases.
Table of contents
TL;DRWhy Not Just Be Careful?The Key MetaphorPrior ArtThe Dual Mechanism DesignGetting a KeyDiagramsno_std and EmbeddedEscape HatchWrap UpSort: