@@ -326,10 +326,10 @@ Rust will assume that an unsuffixed integer literal has type
326
326
` int ` .
327
327
328
328
~~~~
329
- let a = 1; // a is an int
330
- let b = 10i; // b is an int, due to the 'i' suffix
331
- let c = 100u; // c is a uint
332
- let d = 1000i32; // d is an i32
329
+ let a = 1; // `a` is an ` int`
330
+ let b = 10i; // `b` is an ` int` , due to the `i` suffix
331
+ let c = 100u; // `c` is a ` uint`
332
+ let d = 1000i32; // `d` is an ` i32`
333
333
~~~~
334
334
335
335
There are two floating-point types: ` f32 ` , and ` f64 ` .
@@ -400,10 +400,10 @@ error when the types of the directives don't match the types of the arguments.
400
400
~~~~
401
401
# let mystery_object = ();
402
402
403
- // {} will print the "default format" of a type
403
+ // `{}` will print the "default format" of a type
404
404
println!("{} is {}", "the answer", 43);
405
405
406
- // {:?} will conveniently print any type
406
+ // ` {:?}` will conveniently print any type
407
407
println!("what is this thing: {:?}", mystery_object);
408
408
~~~~
409
409
@@ -612,7 +612,7 @@ struct without inherited mutability would result in a type error.
612
612
let mut mypoint = Point { x: 1.0, y: 1.0 };
613
613
let origin = Point { x: 0.0, y: 0.0 };
614
614
615
- mypoint.y += 1.0; // mypoint is mutable, and its fields as well
615
+ mypoint.y += 1.0; // ` mypoint` is mutable, and its fields as well
616
616
origin.y += 1.0; // ERROR: assigning to immutable field
617
617
~~~~
618
618
@@ -1085,8 +1085,8 @@ Avoiding a move can be done with the library-defined `clone` method:
1085
1085
1086
1086
~~~~
1087
1087
let x = ~5;
1088
- let y = x.clone(); // y is a newly allocated box
1089
- let z = x; // no new memory allocated, x can no longer be used
1088
+ let y = x.clone(); // `y` is a newly allocated box
1089
+ let z = x; // no new memory allocated, `x` can no longer be used
1090
1090
~~~~
1091
1091
1092
1092
The ` clone ` method is provided by the ` Clone ` trait, and can be derived for
@@ -1340,7 +1340,7 @@ fn foo() -> (u64, u64, u64, u64, u64, u64) {
1340
1340
(5, 5, 5, 5, 5, 5)
1341
1341
}
1342
1342
1343
- let x = ~foo(); // allocates a ~ box, and writes the integers directly to it
1343
+ let x = ~foo(); // allocates a `~` box, and writes the integers directly to it
1344
1344
~~~~
1345
1345
1346
1346
Beyond the properties granted by the size, an owned box behaves as a regular
@@ -1353,7 +1353,7 @@ y += 2;
1353
1353
1354
1354
let x = ~5; // immutable
1355
1355
let mut y = ~5; // mutable
1356
- *y += 2; // the * operator is needed to access the contained value
1356
+ *y += 2; // the `*` operator is needed to access the contained value
1357
1357
~~~~
1358
1358
1359
1359
# References
@@ -1451,9 +1451,9 @@ of a non-`Freeze` type is [`RefCell<T>`][refcell].
1451
1451
~~~~
1452
1452
let mut x = 5;
1453
1453
{
1454
- let y = &x; // x is now frozen, it cannot be modified
1454
+ let y = &x; // `x` is now frozen, it cannot be modified
1455
1455
}
1456
- // x is now unfrozen again
1456
+ // `x` is now unfrozen again
1457
1457
# x = 3;
1458
1458
~~~~
1459
1459
@@ -1559,7 +1559,7 @@ let mut numbers = ~[1, 2, 3];
1559
1559
numbers.push(4);
1560
1560
numbers.push(5);
1561
1561
1562
- // The type of a unique vector is written as ~ [ int]
1562
+ // The type of a unique vector is written as ` ~[int] `
1563
1563
let more_numbers: ~ [ int] = numbers;
1564
1564
1565
1565
// The original ` numbers ` value can no longer be used, due to move semantics.
@@ -1576,7 +1576,7 @@ the elements.
1576
1576
// A slice
1577
1577
let xs = &[ 1, 2, 3] ;
1578
1578
1579
- // Slices have their type written as &[ int]
1579
+ // Slices have their type written as ` &[int] `
1580
1580
let ys: &[ int] = xs;
1581
1581
1582
1582
// Other vector types coerce to slices
@@ -1586,7 +1586,7 @@ let zs: &[int] = three;
1586
1586
// An unadorned string literal is an immutable string slice
1587
1587
let string = "foobar";
1588
1588
1589
- // A string slice type is written as &str
1589
+ // A string slice type is written as ` &str `
1590
1590
let view: &str = string.slice(0, 3);
1591
1591
~~~
1592
1592
@@ -1600,7 +1600,7 @@ let mut xs = [1, 2, 3];
1600
1600
let view = xs.mut_slice(0, 2);
1601
1601
view[ 0] = 5;
1602
1602
1603
- // The type of a mutable slice is written as &mut [ T]
1603
+ // The type of a mutable slice is written as ` &mut [T] `
1604
1604
let ys: &mut [ int] = &mut [ 1, 2, 3] ;
1605
1605
~~~
1606
1606
@@ -2546,7 +2546,7 @@ that binary is collectively called a 'crate'.
2546
2546
For example, for a simple hello world program your crate only consists of this code:
2547
2547
2548
2548
~~~~
2549
- // main.rs
2549
+ // ` main.rs`
2550
2550
fn main() {
2551
2551
println!("Hello world!");
2552
2552
}
@@ -2675,8 +2675,8 @@ fn main() {
2675
2675
f.farmer.rest();
2676
2676
2677
2677
// This wouldn't compile because both are private:
2678
- // f.feed_chickens();
2679
- // let chicken_counter = f.chickens.len();
2678
+ // ` f.feed_chickens();`
2679
+ // ` let chicken_counter = f.chickens.len();`
2680
2680
}
2681
2681
# fn make_me_a_farm() -> farm::Farm { farm::make_me_a_farm() }
2682
2682
# fn make_me_a_chicken() -> farm::Chicken { 0 }
@@ -2708,8 +2708,8 @@ If it finds both, that's a compile error.
2708
2708
So, if we want to move the content of ` mod farm ` into it's own file, it would look like this:
2709
2709
2710
2710
~~~~ {.ignore}
2711
- // main.rs - contains body of the crate root
2712
- mod farm; // Compiler will look for ' farm.rs' and ' farm/mod.rs'
2711
+ // ` main.rs` - contains body of the crate root
2712
+ mod farm; // Compiler will look for ` farm.rs` and ` farm/mod.rs`
2713
2713
2714
2714
fn main() {
2715
2715
println!("Hello farm!");
@@ -2718,7 +2718,7 @@ fn main() {
2718
2718
~~~~
2719
2719
2720
2720
~~~~
2721
- // farm.rs - contains body of module 'farm' in the crate root
2721
+ // ` farm.rs` - contains body of module 'farm' in the crate root
2722
2722
pub fn chicken() { println!("cluck cluck"); }
2723
2723
pub fn cow() { println!("mooo"); }
2724
2724
@@ -2743,7 +2743,7 @@ is contained in, if any.
2743
2743
For example, given a file with this module body:
2744
2744
2745
2745
~~~ {.ignore}
2746
- // src/main.rs
2746
+ // ` src/main.rs`
2747
2747
mod plants;
2748
2748
mod animals {
2749
2749
mod fish;
@@ -2771,13 +2771,13 @@ depending on how and where you've moved a module body to its own file.
2771
2771
For example, if we move the ` animals ` module above into its own file...
2772
2772
2773
2773
~~~ {.ignore}
2774
- // src/main.rs
2774
+ // ` src/main.rs`
2775
2775
mod plants;
2776
2776
mod animals;
2777
2777
~~~
2778
2778
2779
2779
~~~ {.ignore}
2780
- // src/animals.rs or src/animals/mod.rs
2780
+ // ` src/animals.rs` or ` src/animals/mod.rs`
2781
2781
mod fish;
2782
2782
mod mammals {
2783
2783
mod humans;
@@ -2874,7 +2874,7 @@ use farm::cow;
2874
2874
fn cow() { println!("Mooo!") }
2875
2875
2876
2876
fn main() {
2877
- cow() // resolves to the locally defined cow() function
2877
+ cow() // resolves to the locally defined ` cow()` function
2878
2878
}
2879
2879
~~~
2880
2880
@@ -2924,21 +2924,21 @@ fn main() {
2924
2924
And here an example with multiple files:
2925
2925
2926
2926
~~~ {.ignore}
2927
- // a.rs - crate root
2927
+ // ` a.rs` - crate root
2928
2928
use b::foo;
2929
2929
mod b;
2930
2930
fn main() { foo(); }
2931
2931
~~~
2932
2932
2933
2933
~~~ {.ignore}
2934
- // b.rs
2934
+ // ` b.rs`
2935
2935
use b::c::bar;
2936
2936
pub mod c;
2937
2937
pub fn foo() { bar(); }
2938
2938
~~~
2939
2939
2940
2940
~~~
2941
- // c.rs
2941
+ // ` c.rs`
2942
2942
pub fn bar() { println!("Baz!"); }
2943
2943
# fn main() {}
2944
2944
~~~
@@ -3101,7 +3101,7 @@ without conflict.
3101
3101
Therefore, if you plan to compile your crate as a library, you should annotate it with that information:
3102
3102
3103
3103
~~~~
3104
- // lib.rs
3104
+ // ` lib.rs`
3105
3105
3106
3106
# #[crate_type = "lib"];
3107
3107
// Package ID
@@ -3125,7 +3125,7 @@ Other crate settings and metadata include things like enabling/disabling certain
3125
3125
or setting the crate type (library or executable) explicitly:
3126
3126
3127
3127
~~~~
3128
- // lib.rs
3128
+ // ` lib.rs`
3129
3129
// ...
3130
3130
3131
3131
// This crate is a library ("bin" is the default)
@@ -3144,15 +3144,15 @@ Now for something that you can actually compile yourself.
3144
3144
We define two crates, and use one of them as a library in the other.
3145
3145
3146
3146
~~~~
3147
- // world.rs
3147
+ // ` world.rs`
3148
3148
#[crate_id = "world#0.42"];
3149
3149
# extern mod extra;
3150
3150
pub fn explore() -> &'static str { "world" }
3151
3151
# fn main() {}
3152
3152
~~~~
3153
3153
3154
3154
~~~~ {.ignore}
3155
- // main.rs
3155
+ // ` main.rs`
3156
3156
extern mod world;
3157
3157
fn main() { println!("hello {}", world::explore()); }
3158
3158
~~~~
@@ -3203,7 +3203,7 @@ For example, it re-exports `range` which is defined in `std::iter::range`:
3203
3203
use iter_range = std::iter::range;
3204
3204
3205
3205
fn main() {
3206
- // range is imported by default
3206
+ // ` range` is imported by default
3207
3207
for _ in range(0, 10) {}
3208
3208
3209
3209
// Doesn't hinder you from importing it under a different name yourself
0 commit comments