| 1 | <h2>Comments</h2> |
| 2 | <pre><code>// Single line comment |
| 3 | /// Doc comments |
| 4 | /* Multiline |
| 5 | comment */</code></pre> |
| 6 | |
| 7 | <h2>Strings</h2> |
| 8 | <pre><code>'C'; '\''; '\n'; '\u{7FFF}'; // Characters |
| 9 | "foo \"bar\" baz"; // String |
| 10 | r##"foo #"bar"# baz"##; // Raw string with # pairs |
| 11 | b'C'; b'\''; b'\n'; // Bytes |
| 12 | b"foo \"bar\" baz"; // Byte string |
| 13 | br##"foo #"bar"# baz"##; // Raw byte string with # pairs |
| 14 | </code></pre> |
| 15 | |
| 16 | <h2>Numbers</h2> |
| 17 | <pre><code>0xff_u8; // type u8 |
| 18 | 0o70_i16; // type i16 |
| 19 | 0b1111_1111_1001_0000_i32; // type i32 |
| 20 | |
| 21 | 123.0f64; // type f64 |
| 22 | 0.1f64; // type f64 |
| 23 | 0.1f32; // type f32 |
| 24 | 12E+99_f64; // type f64 |
| 25 | </code></pre> |
| 26 | |
| 27 | <h2>Booleans</h2> |
| 28 | <pre><code>true; false;</code></pre> |
| 29 | |
| 30 | <h2>Functions and macros</h2> |
| 31 | <pre><code>println!("x is {}", x); |
| 32 | fn next_two(x: i32) -> (i32, i32) { (x + 1, x + 2) } |
| 33 | next_two(5); |
| 34 | vec![1, 2, 3]; |
| 35 | </code></pre> |
| 36 | |
| 37 | <h2>Attributes</h2> |
| 38 | <pre><code>#![warn(unstable)] |
| 39 | #[test] |
| 40 | fn a_test() { |
| 41 | // ... |
| 42 | }</code></pre> |
| 43 | |
| 44 | <h2>Closure parameters and bitwise OR</h2> |
| 45 | <pre><code>let x = a | b; |
| 46 | let y = c || d; |
| 47 | let add_one = |x: i32| -> i32 { 1i + x }; |
| 48 | let printer = || { println!("x is: {}", x); }; |
| 49 | </code></pre> |