diff options
author | Aleksey Kladov <[email protected]> | 2020-06-08 11:54:48 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-06-08 11:54:48 +0100 |
commit | cc07c82fefb2affc1772e12b8357471cccc8d578 (patch) | |
tree | 3b4328644c290792a631002be1e5db248bbae11a /docs | |
parent | ee8dec5dc11cfecf219b6510b0eadd9691a82ba5 (diff) |
Preconditions style
Diffstat (limited to 'docs')
-rw-r--r-- | docs/dev/README.md | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/docs/dev/README.md b/docs/dev/README.md index 64d595b68..5a9c0a148 100644 --- a/docs/dev/README.md +++ b/docs/dev/README.md | |||
@@ -241,6 +241,26 @@ struct Foo { | |||
241 | For `.md` and `.adoc` files, prefer a sentence-per-line format, don't wrap lines. | 241 | For `.md` and `.adoc` files, prefer a sentence-per-line format, don't wrap lines. |
242 | If the line is too long, you want to split the sentence in two :-) | 242 | If the line is too long, you want to split the sentence in two :-) |
243 | 243 | ||
244 | ## Preconditions | ||
245 | |||
246 | Function preconditions should generally be expressed in types and provided by the caller (rather than checked by callee): | ||
247 | |||
248 | ```rust | ||
249 | // Good | ||
250 | fn frbonicate(walrus: Walrus) { | ||
251 | ... | ||
252 | } | ||
253 | |||
254 | // Not as good | ||
255 | fn frobnicate(walrus: Option<Walrus>) { | ||
256 | let walrus = match walrus { | ||
257 | Some(it) => it, | ||
258 | None => return, | ||
259 | }; | ||
260 | ... | ||
261 | } | ||
262 | ``` | ||
263 | |||
244 | # Architecture Invariants | 264 | # Architecture Invariants |
245 | 265 | ||
246 | This section tries to document high-level design constraints, which are not | 266 | This section tries to document high-level design constraints, which are not |