File tree Expand file tree Collapse file tree 1 file changed +32
-11
lines changed Expand file tree Collapse file tree 1 file changed +32
-11
lines changed Original file line number Diff line number Diff line change 219219``` rust
220220// Good
221221struct Foo {
222- bars : Vec <Bar >
222+ bars : Vec <Bar >
223223}
224224
225225struct Bar ;
@@ -232,35 +232,56 @@ rather than
232232struct Bar ;
233233
234234struct Foo {
235- bars : Vec <Bar >
235+ bars : Vec <Bar >
236236}
237237```
238238
239- ## Documentation
240-
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 :-)
243-
244239## Preconditions
245240
246241Function preconditions should generally be expressed in types and provided by the caller (rather than checked by callee):
247242
248243``` rust
249244// Good
250245fn frbonicate (walrus : Walrus ) {
251- ...
246+ ...
252247}
253248
254249// Not as good
255250fn frobnicate (walrus : Option <Walrus >) {
256- let walrus = match walrus {
251+ let walrus = match walrus {
252+ Some (it ) => it ,
253+ None => return ,
254+ };
255+ ...
256+ }
257+ ```
258+
259+ ## Premature Pessimization
260+
261+ While we don't specifically optimize code yet, avoid writing the code which is slower than it needs to be.
262+ Don't allocate a ` Vec ` were an iterator would do, don't allocate strings needlessly.
263+
264+ ``` rust
265+ // Good
266+ use itertools :: Itertools ;
267+
268+ let (first_word , second_word ) = match text . split_ascii_whitespace (). collect_tuple () {
257269 Some (it ) => it ,
258270 None => return ,
259- };
260- ...
271+ }
272+
273+ // Not as good
274+ let words = text . split_ascii_whitespace (). collect :: <Vec <_ >>();
275+ if words . len () != 2 {
276+ return
261277}
262278```
263279
280+ ## Documentation
281+
282+ For ` .md ` and ` .adoc ` files, prefer a sentence-per-line format, don't wrap lines.
283+ If the line is too long, you want to split the sentence in two :-)
284+
264285## Commit Style
265286
266287We don't have specific rules around git history hygiene.
You can’t perform that action at this time.
0 commit comments