]> git.lizzy.rs Git - rust.git/blob - src/doc/style/safety/README.md
rollup merge of #22435: aturon/final-stab-thread
[rust.git] / src / doc / style / safety / README.md
1 % Safety and guarantees
2
3 > **[FIXME]** Is there a better phrase than "strong guarantees" that encompasses
4 > both e.g. memory safety and e.g. data structure invariants?
5
6 A _guarantee_ is a property that holds no matter what client code does, unless
7 the client explicitly opts out:
8
9 * Rust guarantees memory safety and data-race freedom, with `unsafe`
10   blocks as an opt-out mechanism.
11
12 * APIs in Rust often provide their own guarantees. For example, `std::str`
13 guarantees that its underlying buffer is valid utf-8. The `std::path::Path` type
14 guarantees no interior nulls. Both strings and paths provide `unsafe` mechanisms
15 for opting out of these guarantees (and thereby avoiding runtime checks).
16
17 Thinking about guarantees is an essential part of writing good Rust code.  The
18 rest of this subsection outlines some cross-cutting principles around
19 guarantees.