hoare_skill
- Python
3
GitHub Stars
1
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill copyleftdev/sk1llz --skill hoare- SKILL.md5.8 KB
Overview
This skill captures Graydon Hoare's original vision for Rust and applies it to writing safe, practical systems code. It emphasizes memory safety without a garbage collector, zero-cost abstractions, and using the type system to eliminate whole classes of bugs common in C and C++. Use it to design APIs and implementations that follow Rust's founding principles.
How this skill works
The skill inspects design and code choices through Hoare-aligned rules: ownership-first thinking, explicit unsafe usage, and preference for stack allocation and Option/Result types. It guides rewrite suggestions, API shapes, and idioms so illegal states become unrepresentable and the borrow checker is treated as a design tool. Recommendations are concrete: prefer &str over String for params, use iterators, and avoid unwraps in library code.
When to use it
- Designing low-level libraries where predictable performance and no GC are required
- Refactoring C/C++ systems code into idiomatic, memory-safe Rust
- Reviewing APIs to ensure states are enforced by types rather than runtime checks
- Teaching Rust concepts rooted in the language's original goals
- Deciding whether unsafe is justified and how to document invariants
Best practices
- Let the borrow checker guide architecture; design around ownership up front
- Make illegal states unrepresentable using enums and type transitions
- Prefer Option<T> and Result<T, E> over nulls and exceptions
- Avoid .unwrap() in libraries; reserve unsafe blocks and document safety invariants
- Favor &str and &[T] for read-only parameters and impl Trait for ergonomic APIs
Example use cases
- Rewriting a C networking component into Rust while ensuring no data races
- Designing a stateful API where transitions are encoded in types (Disconnected -> Connected)
- Auditing a crate for unnecessary heap allocation, replacing Vec with &[T] where appropriate
- Refactoring error handling to use Result and the ? operator throughout
- Evaluating whether a performance hotspot requires unsafe code or can be expressed as a zero-cost abstraction
FAQ
Use unsafe only when necessary for performance or FFI and document the exact invariants that must hold; keep unsafe blocks minimal and encapsulate them behind safe interfaces.
How do I avoid self-referential structs?
Avoid them unless required; prefer design patterns that move ownership out or use Pin and careful APIs only after understanding pinning rules.