Rust — Compile-Time Safety Techniques
Base path:
${CLAUDE_PLUGIN_ROOT}/skills/rust
Full catalog (type system features → constraints they enforce)
Ownership & moves — prevent use-after-free and double-free; ensure deterministic cleanup →
catalog/T10-ownership-moves.mdBorrowing & mutability — eliminate data races and iterator invalidation via aliasing rules (
&Txor&mut T) →catalog/T11-borrowing-mutability.mdLifetimes — prevent dangling references; prove every reference valid for its usage →
catalog/T48-lifetimes.mdStructs, enums, newtypes — make invalid states unrepresentable; exhaustive match forces handling all variants →
catalog/T01-algebraic-data-types.mdGenerics & where clauses — generic code compiles only when operations are justified by declared bounds →
catalog/T04-generics-bounds.mdTraits & impls — enforce contracts on types; one impl per trait-type pair globally →
catalog/T05-type-classes.mdAssociated types & advanced traits — lock output types per implementor; reduce caller confusion →
catalog/T49-associated-types.mdTrait objects (
dyn) — runtime polymorphism when concrete types are unknown; only object-safe traits qualify →catalog/T36-trait-objects.mdInference, aliases, conversions — maintain type safety while permitting local inference; no silent conversions →
catalog/T18-conversions-coercions.mdSmart pointers & interior mutability — flexible ownership (shared, interior-mutable) while preserving memory safety →
catalog/T24-smart-pointers.mdSend & Sync — prevent data races at compile time by controlling what crosses thread boundaries →
catalog/T50-send-sync.mdConst generics — encode sizes, dimensions, capacities in types; distinct values = distinct types →
catalog/T15-const-generics.mdCoherence & orphan rules — prevent conflicting impls across crates; ensure independent publishing →
catalog/T25-coherence-orphan.mdTrait solver & param env — deterministic zero-cost trait resolution; guides correct bounds →
catalog/T37-trait-solver.mdRefinement types — newtype + smart constructor pattern; validated values with private fields; nutype derive macro →
catalog/T26-refinement-types.mdLiteral types — Rust lacks first-class literal types; const generics, enums, and
typenumserve as alternatives →catalog/T52-literal-types.mdPath-dependent types — associated types as path-dependent analogs; GATs for higher-kinded path dependence →
catalog/T53-path-dependent-types.mdNewtypes — zero-cost wrapper types with private fields; prevent value mix-ups →
catalog/T03-newtypes-opaque.mdDerive macros —
#[derive(Debug, Clone, Serialize)]; auto-generate trait impls from structure →catalog/T06-derivation.mdNull safety — no null in Rust;
Option<T>enforces handling of absent values →catalog/T13-null-safety.mdType narrowing —
if let,match,let-else; exhaustive pattern matching →catalog/T14-type-narrowing.mdCompile-time computation —
const fn,constblocks, compile-time evaluation →catalog/T16-compile-time-ops.mdMacros —
macro_rules!, proc macros,syn/quotefor code generation →catalog/T17-macros-metaprogramming.mdEquality safety —
PartialEq/Eqare opt-in; no accidental cross-type equality →catalog/T20-equality-safety.mdEncapsulation —
pub/pub(crate)/private-by-default module system →catalog/T21-encapsulation.mdCallable typing —
Fn/FnMut/FnOncetrait hierarchy; closures and function pointers →catalog/T22-callable-typing.mdType aliases —
type Alias = ConcreteType; transparent aliases vs newtypes →catalog/T23-type-aliases.mdPhantom types —
PhantomData<T>for variance control, typestate, lifetime markers →catalog/T27-erased-phantom.mdRecord types — named-field structs; struct update syntax; destructuring →
catalog/T31-record-types.mdImmutability — immutable by default;
mutis opt-in;constfor compile-time constants →catalog/T32-immutability-markers.mdSelf type —
Selfrefers to the implementing type; builders,From/Into→catalog/T33-self-type.mdNever type —
!bottom type;Infallible; empty enums; coerces to any type →catalog/T34-never-bottom.mdUnion types (via enums) — enums as sum types; trait bounds as intersection →
catalog/T02-union-intersection.mdStructural typing (via traits) — nominal typing with trait-based contracts →
catalog/T07-structural-typing.mdVariance (implicit rules) — compiler-inferred variance;
PhantomDatafor control →catalog/T08-variance-subtyping.mdEffect tracking (via Result) —
Result<T,E>+?;async/await;unsafeboundaries →catalog/T12-effect-tracking.mdExtension methods (via traits) — extension trait pattern; orphan rules →
catalog/T19-extension-methods.mdFunctor / Monad (via Iterator/Option/Result) — map, and_then, ? operator →
catalog/T54-functor-applicative-monad.mdMonad transformers (via middleware) — tower layers, async middleware →
catalog/T55-monad-transformers.mdTagless final (via trait DI) — trait-based dependency injection →
catalog/T56-tagless-final.mdTypestate pattern — PhantomData for zero-cost state encoding; canonical Rust pattern →
catalog/T57-typestate.mdWitness types (via PhantomData markers) — compile-time evidence of preconditions →
catalog/T58-witness-evidence.mdExistential types — dyn Trait, impl Trait; type erasure with contracts →
catalog/T59-existential-types.mdLinear / affine types — ownership IS linear typing; each value used at most once →
catalog/T60-linear-affine.mdRecursive types — enum + Box for indirection; compiler requires known size →
catalog/T61-recursive-types.md
Use cases (problem → which features help)
- Preventing invalid states — represent only valid domain states so invalid combinations won't compile (enums, newtypes, phantom types) →
usecases/UC01-invalid-states.md - Ownership-safe APIs — encode ownership transfer, borrowing, and lifetimes in signatures to prevent use-after-free in caller code →
usecases/UC20-ownership-apis.md - Generic capability constraints — accept only types satisfying required traits; reject unsuitable types with clear errors →
usecases/UC04-generic-constraints.md - Extensible polymorphic interfaces — allow plugins/alternative implementations without losing compile-time safety →
usecases/UC14-extensibility.md - Compile-time concurrency — threaded code compiles only when transfer and sharing are safe (
Send/Sync) →usecases/UC21-concurrency.md - Value-level invariants with types — encode lengths, dimensions, shapes in types so mismatches are caught at compile time →
usecases/UC18-type-arithmetic.md
Source: jpablo/vibe-types — distributed by TomeVault.