new pattern: Contain Unsafety in Small Modules

pull/75/head
Andre Bogus 6 years ago
parent aa886569ed
commit db86d28e5a

@ -1,4 +1,4 @@
# Contain Unsafety in Small Modules
# Contain unsafety in small modules
## Description
@ -16,7 +16,7 @@ If you have `unsafe` code, create the smallest possible module that can uphold t
## Examples
* The [`optional`](https://crates.io/crates/optional) crate has one unsafe module for converting a `&T` to either a slice of one `[T]` or an empty slice.
* The [`toolshed`](https://docs.rs/toolshed) crate contains its unsafe operations in submodules, presenting a safe interface to users.
* `std`s `String` class is a wrapper over `Vec<u8>` with the added invariant that the contents must be valid UTF-8. The operations on `String` ensure this behavior. However, users have the option of using an `unsafe` method to create a `String`, in which case the onus is on them to guarantee the validity of the contents.
## See also

Loading…
Cancel
Save