Skip to content

Latest commit

 

History

History
94 lines (68 loc) · 1.53 KB

STYLE.md

File metadata and controls

94 lines (68 loc) · 1.53 KB

Rust Style Guide

Please write good Rust.

Table of Contents

  1. Unsafe
  2. Whitespace
  3. Dereferences
  4. Use Statements

Unsafe

No use of the unsafe keyword is allowed. This guideline is statically enforced.

Whitespace

All curly brace blocks will have at least one line return between the opening brace and the closing brace. The opening curly brace of keyword blocks (e.g. impl) will be placed on the same line as the keyword.

Bad
impl Project { pub fn new() -> Project { ... } }
Good
impl Project { 
  pub fn new() -> Project {
    ...
  }
}

All else and else if blocks will begin on the same line as the previous closing curly brace.

Bad
if arg.is_present("bin") { ... }
else if arg.is_present("static") { ... }
else { ... }
Good
if arg.is_present("bin") {
  ...
} else if arg.is_present("static") {
  ...
} else {
  ...
}

Dereferences

When y is a reference, the asterisk operator used to dereference y should contain no whitespace between the operator and the reference.

Bad
match * y {
  ...
}
Good
match *y {
  ...
}

When *y is a reference the same styling as above should be used.

Use Statements

When importing names from a module, only use the bracket notation when importing multiple names.

Bad
use project::{ Project };
Good
use project::Project;
use Foo::{ Bar, Baz };