about summary refs log tree commit diff
path: root/docs/dev
diff options
context:
space:
mode:
authorAleksey Kladov <aleksey.kladov@gmail.com>2020-06-08 12:54:48 +0200
committerAleksey Kladov <aleksey.kladov@gmail.com>2020-06-08 12:54:48 +0200
commitcc07c82fefb2affc1772e12b8357471cccc8d578 (patch)
tree3b4328644c290792a631002be1e5db248bbae11a /docs/dev
parentee8dec5dc11cfecf219b6510b0eadd9691a82ba5 (diff)
downloadrust-cc07c82fefb2affc1772e12b8357471cccc8d578.tar.gz
rust-cc07c82fefb2affc1772e12b8357471cccc8d578.zip
Preconditions style
Diffstat (limited to 'docs/dev')
-rw-r--r--docs/dev/README.md20
1 files changed, 20 insertions, 0 deletions
diff --git a/docs/dev/README.md b/docs/dev/README.md
index 64d595b684a..5a9c0a148a1 100644
--- a/docs/dev/README.md
+++ b/docs/dev/README.md
@@ -241,6 +241,26 @@ struct Foo {
 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 :-)
 
+## 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
 
 This section tries to document high-level design constraints, which are not