Skip to content

Commit 87a0765

Browse files
committed
doc: add that or blocks may end with default values
1 parent f61a7bf commit 87a0765

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

doc/docs.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,8 +1373,14 @@ fn (r Repo) find_user_by_id(id int) ?User {
13731373
13741374
fn main() {
13751375
repo := new_repo()
1376-
user := repo.find_user_by_id(10) or { // Option types must be handled by `or` blocks
1377-
return // `or` block must end with `return`, `break`, or `continue`
1376+
user := repo.find_user_by_id(10) or {
1377+
// Option types must be handled by `or` blocks.
1378+
// Any `or` block, *must* end with one of:
1379+
// a) `break`, `continue` or `return` .
1380+
// b) a panic("message") or exit(code) call .
1381+
// c) a default value of the same type as the Option .
1382+
// (i.e. if the function returns for example ?int, you may put 1234 as default value)
1383+
return
13781384
}
13791385
println(user.id) // "10"
13801386
println(user.name) // "Charles"

0 commit comments

Comments
 (0)