mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Preconditions style
This commit is contained in:
parent
ee8dec5dc1
commit
cc07c82fef
1 changed files with 20 additions and 0 deletions
|
@ -241,6 +241,26 @@ struct Foo {
|
||||||
For `.md` and `.adoc` files, prefer a sentence-per-line format, don't wrap lines.
|
For `.md` and `.adoc` files, prefer a sentence-per-line format, don't wrap lines.
|
||||||
If the line is too long, you want to split the sentence in two :-)
|
If the line is too long, you want to split the sentence in two :-)
|
||||||
|
|
||||||
|
## Preconditions
|
||||||
|
|
||||||
|
Function preconditions should generally be expressed in types and provided by the caller (rather than checked by callee):
|
||||||
|
|
||||||
|
```rust
|
||||||
|
// Good
|
||||||
|
fn frbonicate(walrus: Walrus) {
|
||||||
|
...
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not as good
|
||||||
|
fn frobnicate(walrus: Option<Walrus>) {
|
||||||
|
let walrus = match walrus {
|
||||||
|
Some(it) => it,
|
||||||
|
None => return,
|
||||||
|
};
|
||||||
|
...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
# Architecture Invariants
|
# Architecture Invariants
|
||||||
|
|
||||||
This section tries to document high-level design constraints, which are not
|
This section tries to document high-level design constraints, which are not
|
||||||
|
|
Loading…
Reference in a new issue