rust-unofficial / patterns

A catalogue of Rust design patterns, anti-patterns and idioms
https://rust-unofficial.github.io/patterns/
Mozilla Public License 2.0
8.11k stars 375 forks source link

Pattern: contain unsafety in small module #74

Closed llogiq closed 5 years ago

llogiq commented 5 years ago

When dealing with unsafe code, the containing module has to ensure safety by upholding invariants. To make this feasible, the module should be as small as possible, only containing the unsafe functionality and the code necessary to uphold the guarantees, and embedding this in a larger module that can safely use the abstraction.

This keeps the code needed for an unsafe audit in manageable size.