safe-over-unsafe

Design safe Rust public APIs that abstract over unsafe code.

1|Updated Feb 12, 2026
One-click install
npx skills add https://github.com/ahrav/Gossip-rs --skill safe-over-unsafe
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: safe-over-unsafe
Source: https://github.com/ahrav/Gossip-rs/tree/main/.claude/skills/safe-over-unsafe
Command: npx skills add https://github.com/ahrav/Gossip-rs --skill safe-over-unsafe

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides guidance and best practices for designing safe, public-facing APIs in Rust that wrap potentially unsafe underlying code, ensuring memory safety and preventing undefined behavior.

Core Features & Use Cases

  • API Design: Learn how to create robust and secure APIs by encapsulating unsafe Rust code.
  • Soundness Review: Understand how to review existing unsafe code for potential bugs and vulnerabilities.
  • Type Safety: Implement new types backed by raw pointers, MaybeUninit, or FFI with confidence.
  • Use Case: When developing a library that needs to interact with C code via FFI, this Skill helps you build a safe Rust interface that hides the complexities and risks of the raw FFI calls.

Quick Start

Use the safe-over-unsafe skill to review the provided unsafe Rust code snippet for soundness.

Frequently Asked Questions about safe-over-unsafe

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I design a safe Rust API over unsafe code?

To design a safe Rust API over unsafe code, encapsulate unsafe operations in private fields and expose public methods that enforce invariants and panic safety. This abstraction prevents undefined behavior by ensuring all inputs and states remain valid.

How do I wrap raw Rust pointers and MaybeUninit in a safe public interface?

Wrapping raw Rust pointers and MaybeUninit requires creating new types that guarantee initialization and aliasing rules before public exposure. You enforce these memory safety invariants via compile-time checks to prevent undefined behavior.

What is soundness review in Rust unsafe code?

Soundness review in Rust unsafe code is the process of verifying that public APIs cannot trigger undefined behavior regardless of user input. It involves checking raw pointer validity, enforcing invariants, and ensuring panic safety to maintain memory safety guarantees.

How do I build a safe Rust interface for C code via FFI?

Building a safe Rust interface for C code via FFI involves wrapping the raw FFI calls in a safe Rust abstraction. You manage raw pointers and enforce memory safety invariants privately, preventing undefined behavior from leaking into the public API.

When do I need manual Send and Sync implementations in Rust?

Manual Send and Sync implementations in Rust are needed when creating custom types backed by raw pointers or FFI that cross thread boundaries. You must verify thread safety invariants manually because the compiler cannot automatically prove memory safety for unsafe code.

What are the limitations of abstracting over unsafe Rust code?

Abstracting over unsafe Rust code requires rigorously maintaining invariants and panic safety, which can introduce runtime overhead or complexity. Limitations include the constant risk of undefined behavior if internal safety checks fail or if raw pointer validity is misjudged.