skills/safe-rust/SKILL.md
Enforce "safe-rust" coding principles. Use when writing, reading, reviewing, or refactoring Rust code to ensure maximum memory safety, predictable execution, zero-cost abstractions, and idiomatic Rust patterns.
npx skillsauth add thedumptruck/skills safe-rustInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Build highly predictable, robust, and performant Rust applications with strict adherence to ownership, lifetimes, and type-driven safety.
Always verify standards against the reference documentation before implementing.
| Resource | URL / Path |
|----------|------------|
| Memory & Safety | ./references/safety.md |
| Performance Patterns | ./references/performance.md |
| Developer Experience | ./references/dx.md |
Review the relevant documentation when writing new logic or performing code reviews.
./references/safety.md - Ownership, lifetimes, unsafe boundaries, error handling, unwrap/expect policies../references/performance.md - Allocation minimization, Cow, references vs. values, concurrency primitives../references/dx.md - Typestates, Newtype pattern, standard library traits (From, AsRef), Clippy lints.Search: unwrap, unsafe, clippy::pedantic, Cow, Result, Rc, Arc, Mutex
| Need | Example |
|------|---------|
| Compile-Time Safety | Typestate pattern to prevent invalid state transitions |
| Memory Stability | Passing by reference (&T), reusing allocations, Cow<T> |
| Operational Reliability | Exhaustive pattern matching, Result over panic!, thiserror/anyhow |
| Maintainability | Implement From, TryFrom, AsRef, Display; document unsafe |
unwrap() or expect() in production code (unless proving mathematically impossible to fail)unsafe without a heavily documented // SAFETY: comment explaining invariants.clone() or allocations (String, Vec) in hot paths when &str or &[T] worksRc<RefCell<T>> or Arc<Mutex<T>> as the first tool for state sharing (prefer structural borrowing or message passing)// Use the type system to enforce valid state transitions at compile time
struct Unverified;
struct Verified;
struct Email<State> {
address: String,
_state: std::marker::PhantomData<State>,
}
impl Email<Unverified> {
fn new(address: String) -> Self {
Self { address, _state: std::marker::PhantomData }
}
fn verify(self) -> Result<Email<Verified>, &'static str> {
if self.address.contains('@') {
Ok(Email { address: self.address, _state: std::marker::PhantomData })
} else {
Err("Invalid email format")
}
}
}
// This function only accepts verified emails
fn send_welcome(email: &Email<Verified>) {
// ...
}
use std::borrow::Cow;
// Returns a reference if no changes needed, or an allocated String if modified
fn sanitize_input<'a>(input: &'a str) -> Cow<'a, str> {
if input.contains('\0') {
let mut cleaned = input.replace('\0', "");
Cow::Owned(cleaned)
} else {
Cow::Borrowed(input)
}
}
unwrap(), expect(), array indexing arr[i] (prefer arr.get(i)). Handle all errors gracefully via Result and ?.unsafe - If unsafe is absolutely necessary for FFI or extreme performance, every unsafe block must be preceded by a // SAFETY: ... comment proving the invariants.&T, &[T], and &str over T, Vec<T>, and String for function arguments unless ownership is required.struct UserId(u64)) to prevent unit confusion. Use typestates for state machines.#![warn(clippy::pedantic)] as the baseline. Explicitly #[allow(...)] with comments if deviating.mpsc or crossbeam) or Arc<T> (read-only) rather than defaulting to Arc<Mutex<T>>.Default, From, TryFrom, AsRef, and Display instead of custom conversion/instantiation methods.thiserror for library error types (to provide explicit enum variants) and anyhow for application entry points/handlers.#[inline] for hot paths to allow the compiler to optimize without runtime overhead._ in a match statement on an enum unless explicitly intending to ignore all future variants. Force the compiler to check exhaustiveness..clone() to appease the borrow checker instead of fixing lifetimes/architecture.unsafe just to bypass borrow checker limitations without sound reasoning.catch_unwind) as a general error handling mechanism.String or Vec from parsing functions that could just return slices (&str, &[T]) borrowed from the input.development
Enforce "safe-ts" coding principles in TypeScript. Use when writing, reading, reviewing, or refactoring TypeScript code to ensure maximum safety, predictable execution, and zero technical debt.
development
Enforce "safe-golang" coding principles in Go. Use when writing, reading, reviewing, or refactoring Go code to ensure maximum safety, predictable execution, and zero technical debt.
development
Enforce "safe-c" coding principles in C. Based on TigerBeetle's Tiger Style. Use when writing, reading, reviewing, or refactoring C code to ensure maximum safety, predictable execution, zero technical debt, and extreme performance.
development
Maintainer-only workflow for handling GitHub Secret Scanning alerts on OpenClaw. Use when Codex needs to triage, redact, clean up, and resolve secret leakage found in issue comments, issue bodies, PR comments, or other GitHub content.