Skip to content

Commit 1076b36

Browse files
vapdrsfelix91gr
andauthored
Adding more explanation to the examples
Co-authored-by: Félix Fischer <felix91gr@users.noreply.github.com>
1 parent d8222db commit 1076b36

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/coding-guidelines/expressions.rst

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ Expressions
121121
.. code-block:: rust
122122
123123
let x = 0;
124-
let x = 5 / x;
124+
let y = 5 / x; // This line will panic.
125125
126126
.. compliant_example::
127127
:id: compl_ex_Ri9pP5Ch3kbb
@@ -135,18 +135,19 @@ Expressions
135135

136136
.. code-block:: rust
137137
138+
// Example 1: using the checked division API
138139
let result = match 5u8.checked_div(0) {
139140
None => 0
140141
Some(r) => r
141142
};
142-
143+
144+
// Example 2: performing zero-checks by hand
143145
let x = 0;
144-
if (x != 0) {
145-
let x = 5 / x;
146-
}
147-
else {
148-
let x = 0;
149-
}
146+
let y = if x != 0 {
147+
5 / x
148+
} else {
149+
0
150+
};
150151
151152
152153

0 commit comments

Comments
 (0)