rust-compile-time-invariants

Installation
SKILL.md

Rust Compile-Time Invariants

Core rule: put the compiler in charge of enforcing invariants. Every pattern below converts a runtime check or convention into a compile error when the type evolves.

Construction & invariants

Need Construct
Force validation on every instance (intra-crate) Add _private: () field; only the validating new() can fill it
Same, but block even same-module bypasses Nested module + private Seal struct; pub use inner::S
Force callers through constructor at crate boundary #[non_exhaustive] on the struct/enum
Mark a value that must be consumed #[must_use = "Configuration must be applied to take effect"]
Conversion that can fail TryFrom<T>, never From<T> with unwrap_or_else

_private: () enforces intra-crate; #[non_exhaustive] enforces cross-crate. Pick by scope.

Pattern matching that survives refactors

Installs
15
First Seen
May 27, 2026