We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 6eddcfd + d7ece30 commit 951c7c1Copy full SHA for 951c7c1
docs/dev/style.md
@@ -181,6 +181,30 @@ fn frobnicate(walrus: Option<Walrus>) {
181
}
182
```
183
184
+# Early Returns
185
+
186
+Do use early returns
187
188
+```rust
189
+// Good
190
+fn foo() -> Option<Bar> {
191
+ if !condition() {
192
+ return None;
193
+ }
194
195
+ Some(...)
196
+}
197
198
+// Not as good
199
200
+ if condition() {
201
202
+ } else {
203
+ None
204
205
206
+```
207
208
# Getters & Setters
209
210
If a field can have any value without breaking invariants, make the field public.
@@ -189,7 +213,7 @@ Never provide setters.
213
214
Getters should return borrowed data:
215
-```
216
217
struct Person {
218
// Invariant: never empty
219
first_name: String,
0 commit comments