Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Isolate and review unsafe Rust behind small, documented, testable boundaries with explicit invariants. Use when writing, refactoring, or reviewing unsafe code, raw pointers, unsafe functions, unsafe traits, MaybeUninit, pointer aliasing, panic safety, Miri checks, or safe abstractions over unsafe internals.
.claude/skills/hashgraph-online-rust-unsafe-boundaries/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | 1% | 0% |
| case-07 | ✗→✓ | ▲ Improved | -5% | 0% |
| case-10 | ✗→✓ | ▲ Improved | 41% | 0% |
| case-11 | ✗→✓ | ▲ Improved | -14% | 0% |
| case-12 | ✗→✓ | ▲ Improved | -8% | 0% |
Use this skill to isolate unsafe Rust behind small, documented, testable boundaries. Unsafe code is acceptable only when a safe API cannot express the needed operation with acceptable correctness and performance.
iterators, synchronization primitives, and existing crates.
written down, do not write unsafe code yet.
block.
// SAFETY: comment immediately before each unsafe block explainingwhy every unsafe operation inside is valid.
unsafe fn only when callers must uphold extra conditions.Document those conditions in a # Safety section.
unsafe_op_in_unsafe_fn; unsafe operations inside unsafefunctions should still be wrapped in explicit unsafe blocks.
Miri when the project supports it.
Read references/safety-invariants.md before adding or approving unsafe code.
MaybeUninit<T> over deprecated or ad hoc uninitialized memorypatterns.
initialization, aliasing, and lifetime are all proven.
set_len, pointer arithmetic, or from_raw_parts without provingcapacity, initialization, and ownership.
length changes are involved.
static mut; prefer OnceLock, LazyLock, atomics, or locked state.rust/// # Safety /// /// `ptr` must be non-null, aligned for `T`, initialized, and valid for reads /// for the returned lifetime. No mutable reference may alias the same value. pub unsafe fn read_ref<'a, T>(ptr: *const T) -> &'a T { // SAFETY: The caller guarantees `ptr` satisfies the documented contract. unsafe { &*ptr } }
SAFETY explanation.unsafe fn or unsafe trait has a # Safety contract.Other measured skills in the registry, with their headline benchmark lift.