Tutorial by Examples

Line Length // Lines should never exceed 100 characters. // Instead, just wrap on to the next line. let bad_example = "So this sort of code should never really happen, because it's really hard to fit on the screen!"; Indentation // You should always use 4 spaces for indentation. ...
Preludes and Re-Exports // To reduce the amount of imports that users need, you should // re-export important structs and traits. pub use foo::Client; pub use bar::Server; Sometimes, crates use a prelude module to contain important structs, just like std::io::prelude. Usually, these are impor...
You should order your imports and declarations like so: extern crate declarations use imports External imports from other crates should come first Re-exports (pub use)
Structs // Structs use UpperCamelCase. pub struct Snafucator { } mod snafucators { // Try to avoid 'stuttering' by repeating // the module name in the struct name. // Bad: pub struct OrderedSnafucator { } // Good: pub struct Ordered { ...
Type Annotations // There should be one space after the colon of the type // annotation. This rule applies in variable declarations, // struct fields, functions and methods. // GOOD: let mut buffer: String = String::new(); // BAD: let mut buffer:String = String::new(); let mut buffer : Str...

Page 1 of 1