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