Rust Unsafe

Unsafe code and FFI expert covering raw pointers (*mut, *const), FFI patterns, transmute, union, #[repr(C)], SAFETY comments, soundness rules, and undefined behavior prevention.

49 stars 7 forksSoftware Development

Install

skills CLI (Claude Code, Cursor, Codex and more)
npx skills add huiali/rust-skills --skill rust-unsafe
Manual install
git clone --depth 1 https://github.com/huiali/rust-skills.git /tmp/rust-skills
mkdir -p ~/.claude/skills
cp -r /tmp/rust-skills/.codex/skills/rust-unsafe ~/.claude/skills/rust-unsafe

Personal skills live in ~/.claude/skills. Use .claude/skills in a project folder to share a skill with your team.

From the SKILL.md

## When Unsafe is Justified

| Use Case | Example | Justified? |
|----------|---------|-----------|
| FFI calls to C | `extern "C" { fn libc_malloc(size: usize) -> *mut c_void; }` | ✅ Yes |
| Low-level abstractions | Internal implementation of `Vec`, `Arc` | ✅ Yes |
| Performance optimization (measured) | Hot path with proven bottleneck | ⚠️ Verify first |
| Escaping borrow checker | Don't know why you need it | ❌ No |

## SAFETY Comment Requirements

**Every unsafe block must include a SAFETY comment:**

```rust
// SAFETY: ptr must be non-null and properly aligned.
// This function is only called after a null check.
unsafe { *ptr = value; }

/// # Safety
///
/// * `ptr` must be properly aligned and not null
/// * `ptr` must point to initialized memory of type T
/// * The memory must not be accessed after this function returns
pub unsafe fn write(ptr: *mut T, value: &T) { ... }
```

## Solution Patterns

### Pattern 1: FFI with Safe Wrapper

```rust
use std::ffi::{CStr, CString};
use std::os::raw::c_char;

extern "C" {
    fn c_function(s: *const c_char) -> i32;
}

// ✅ Safe wrapper
pub fn safe_c_function(s: &str) -> Result<i32, Box<dyn Error>> {
    let c_str = CString::new(s)?;
    // SAFETY: c_str is a valid null-terminated string created from Rust data.
    // The pointer is valid for the duration of this call.
    let result = unsafe { c_function(c_str.as_ptr()) };
    Ok(result)
}
```

### Pattern 2: Raw Pointer with Validation
Read the full skill on GitHub

Details

Skill name
rust-unsafe
Path
.codex/skills/rust-unsafe/SKILL.md
License
MIT
Repo updated
9 February 2026

FAQ

What does the Rust Unsafe skill do?

Unsafe code and FFI expert covering raw pointers (*mut, *const), FFI patterns, transmute, union, #[repr(C)], SAFETY comments, soundness rules, and undefined behavior prevention.

How do I install the Rust Unsafe skill?

skills CLI (Claude Code, Cursor, Codex and more): npx skills add huiali/rust-skills --skill rust-unsafe. Skills go in ~/.claude/skills (personal) or .claude/skills (project), and Claude loads them automatically when a task matches the description.

Is Rust Unsafe popular?

It lives in huiali/rust-skills, which has 49 GitHub stars and 7 forks.

Related skills

Rust Actor

49

huiali/rust-skills

Actor model expert covering message passing, state isolation, supervision trees, deadlock prevention, fault tolerance, Actix framework, and Erlang-style concurrency patterns.

Software Development

Rust Anti Pattern

49

huiali/rust-skills

Rust anti-patterns and common mistakes expert. Handles code review issues with clone abuse, unwrap in production, String misuse, index loops, and refactoring guidance.

Software Development

Rust Async

49

huiali/rust-skills

Advanced async patterns expert. Handles Stream processing, backpressure control, select/join operations, cancellation, Future trait implementation, and async runtime optimization.

Software Development

Rust Web

49

huiali/rust-skills

Rust web development expert covering HTTP frameworks (axum, actix), REST API design, handler patterns, state management, middleware, database integration, and domain-driven architecture.

Software Development

Rust Type Driven

49

huiali/rust-skills

Type-driven design expert covering newtype pattern, type state, PhantomData, marker traits, builder pattern, compile-time validation, sealed traits, and zero-sized types (ZST).

Software Development

Rust Xacml

49

huiali/rust-skills

策略引擎、权限决策、RBAC、策略模式、责任链--- # Rust XACML - 策略引擎技能 > 本技能提供策略决策引擎的通用解决方案,包括 RBAC、责任链、策略模式等。 ## 核心概念 ### 1. 策略引擎架构 ``` 策略决策流程 ┌─────────────────────────────────────────────────────────────┐ │ 请求上下文 │ │ (主体、资源、操作、环境) │ └────────────────────────┬────────────────────────────────────┘ ▼ ┌─────────────────────────────────────────────────────────────┐ │ 策略决策点 (PDP) │ │ ├── 策略加载 │ │ ├── 策略评估 │ │ └── 决策组合 │ └────────────────────────┬────────────────────────────────────┘ ▼ ┌─────────────────────────────────────────────────────────────┐ │ 决策结果 │ │ (Permit / Deny / NotApplicable / Indeterminate) │ └─────────

Software Development

Browse the most popular Claude skills, all software development skills, or write your own with the skills generator.