Skip to content

Commit 6ad383e

Browse files
committed
doc: use backticks for code-in-comments.
1 parent 3e0eb3c commit 6ad383e

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

doc/tutorial.md

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -326,10 +326,10 @@ Rust will assume that an unsuffixed integer literal has type
326326
`int`.
327327

328328
~~~~
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`
333333
~~~~
334334

335335
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.
400400
~~~~
401401
# let mystery_object = ();
402402
403-
// {} will print the "default format" of a type
403+
// `{}` will print the "default format" of a type
404404
println!("{} is {}", "the answer", 43);
405405
406-
// {:?} will conveniently print any type
406+
// `{:?}` will conveniently print any type
407407
println!("what is this thing: {:?}", mystery_object);
408408
~~~~
409409

@@ -612,7 +612,7 @@ struct without inherited mutability would result in a type error.
612612
let mut mypoint = Point { x: 1.0, y: 1.0 };
613613
let origin = Point { x: 0.0, y: 0.0 };
614614
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
616616
origin.y += 1.0; // ERROR: assigning to immutable field
617617
~~~~
618618

@@ -1085,8 +1085,8 @@ Avoiding a move can be done with the library-defined `clone` method:
10851085

10861086
~~~~
10871087
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
10901090
~~~~
10911091

10921092
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) {
13401340
(5, 5, 5, 5, 5, 5)
13411341
}
13421342
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
13441344
~~~~
13451345

13461346
Beyond the properties granted by the size, an owned box behaves as a regular
@@ -1353,7 +1353,7 @@ y += 2;
13531353
13541354
let x = ~5; // immutable
13551355
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
13571357
~~~~
13581358

13591359
# References
@@ -1451,9 +1451,9 @@ of a non-`Freeze` type is [`RefCell<T>`][refcell].
14511451
~~~~
14521452
let mut x = 5;
14531453
{
1454-
let y = &x; // x is now frozen, it cannot be modified
1454+
let y = &x; // `x` is now frozen, it cannot be modified
14551455
}
1456-
// x is now unfrozen again
1456+
// `x` is now unfrozen again
14571457
# x = 3;
14581458
~~~~
14591459
@@ -1559,7 +1559,7 @@ let mut numbers = ~[1, 2, 3];
15591559
numbers.push(4);
15601560
numbers.push(5);
15611561

1562-
// The type of a unique vector is written as ~[int]
1562+
// The type of a unique vector is written as `~[int]`
15631563
let more_numbers: ~[int] = numbers;
15641564

15651565
// The original `numbers` value can no longer be used, due to move semantics.
@@ -1576,7 +1576,7 @@ the elements.
15761576
// A slice
15771577
let xs = &[1, 2, 3];
15781578

1579-
// Slices have their type written as &[int]
1579+
// Slices have their type written as `&[int]`
15801580
let ys: &[int] = xs;
15811581

15821582
// Other vector types coerce to slices
@@ -1586,7 +1586,7 @@ let zs: &[int] = three;
15861586
// An unadorned string literal is an immutable string slice
15871587
let string = "foobar";
15881588

1589-
// A string slice type is written as &str
1589+
// A string slice type is written as `&str`
15901590
let view: &str = string.slice(0, 3);
15911591
~~~
15921592
@@ -1600,7 +1600,7 @@ let mut xs = [1, 2, 3];
16001600
let view = xs.mut_slice(0, 2);
16011601
view[0] = 5;
16021602

1603-
// The type of a mutable slice is written as &mut [T]
1603+
// The type of a mutable slice is written as `&mut [T]`
16041604
let ys: &mut [int] = &mut [1, 2, 3];
16051605
~~~
16061606
@@ -2546,7 +2546,7 @@ that binary is collectively called a 'crate'.
25462546
For example, for a simple hello world program your crate only consists of this code:
25472547

25482548
~~~~
2549-
// main.rs
2549+
// `main.rs`
25502550
fn main() {
25512551
println!("Hello world!");
25522552
}
@@ -2675,8 +2675,8 @@ fn main() {
26752675
f.farmer.rest();
26762676
26772677
// 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();`
26802680
}
26812681
# fn make_me_a_farm() -> farm::Farm { farm::make_me_a_farm() }
26822682
# fn make_me_a_chicken() -> farm::Chicken { 0 }
@@ -2708,8 +2708,8 @@ If it finds both, that's a compile error.
27082708
So, if we want to move the content of `mod farm` into it's own file, it would look like this:
27092709

27102710
~~~~ {.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`
27132713
27142714
fn main() {
27152715
println!("Hello farm!");
@@ -2718,7 +2718,7 @@ fn main() {
27182718
~~~~
27192719

27202720
~~~~
2721-
// farm.rs - contains body of module 'farm' in the crate root
2721+
// `farm.rs` - contains body of module 'farm' in the crate root
27222722
pub fn chicken() { println!("cluck cluck"); }
27232723
pub fn cow() { println!("mooo"); }
27242724
@@ -2743,7 +2743,7 @@ is contained in, if any.
27432743
For example, given a file with this module body:
27442744

27452745
~~~ {.ignore}
2746-
// src/main.rs
2746+
// `src/main.rs`
27472747
mod plants;
27482748
mod animals {
27492749
mod fish;
@@ -2771,13 +2771,13 @@ depending on how and where you've moved a module body to its own file.
27712771
For example, if we move the `animals` module above into its own file...
27722772

27732773
~~~ {.ignore}
2774-
// src/main.rs
2774+
// `src/main.rs`
27752775
mod plants;
27762776
mod animals;
27772777
~~~
27782778

27792779
~~~ {.ignore}
2780-
// src/animals.rs or src/animals/mod.rs
2780+
// `src/animals.rs` or `src/animals/mod.rs`
27812781
mod fish;
27822782
mod mammals {
27832783
mod humans;
@@ -2874,7 +2874,7 @@ use farm::cow;
28742874
fn cow() { println!("Mooo!") }
28752875
28762876
fn main() {
2877-
cow() // resolves to the locally defined cow() function
2877+
cow() // resolves to the locally defined `cow()` function
28782878
}
28792879
~~~
28802880

@@ -2924,21 +2924,21 @@ fn main() {
29242924
And here an example with multiple files:
29252925

29262926
~~~{.ignore}
2927-
// a.rs - crate root
2927+
// `a.rs` - crate root
29282928
use b::foo;
29292929
mod b;
29302930
fn main() { foo(); }
29312931
~~~
29322932

29332933
~~~{.ignore}
2934-
// b.rs
2934+
// `b.rs`
29352935
use b::c::bar;
29362936
pub mod c;
29372937
pub fn foo() { bar(); }
29382938
~~~
29392939

29402940
~~~
2941-
// c.rs
2941+
// `c.rs`
29422942
pub fn bar() { println!("Baz!"); }
29432943
# fn main() {}
29442944
~~~
@@ -3101,7 +3101,7 @@ without conflict.
31013101
Therefore, if you plan to compile your crate as a library, you should annotate it with that information:
31023102

31033103
~~~~
3104-
// lib.rs
3104+
// `lib.rs`
31053105
31063106
# #[crate_type = "lib"];
31073107
// Package ID
@@ -3125,7 +3125,7 @@ Other crate settings and metadata include things like enabling/disabling certain
31253125
or setting the crate type (library or executable) explicitly:
31263126

31273127
~~~~
3128-
// lib.rs
3128+
// `lib.rs`
31293129
// ...
31303130
31313131
// This crate is a library ("bin" is the default)
@@ -3144,15 +3144,15 @@ Now for something that you can actually compile yourself.
31443144
We define two crates, and use one of them as a library in the other.
31453145

31463146
~~~~
3147-
// world.rs
3147+
// `world.rs`
31483148
#[crate_id = "world#0.42"];
31493149
# extern mod extra;
31503150
pub fn explore() -> &'static str { "world" }
31513151
# fn main() {}
31523152
~~~~
31533153

31543154
~~~~ {.ignore}
3155-
// main.rs
3155+
// `main.rs`
31563156
extern mod world;
31573157
fn main() { println!("hello {}", world::explore()); }
31583158
~~~~
@@ -3203,7 +3203,7 @@ For example, it re-exports `range` which is defined in `std::iter::range`:
32033203
use iter_range = std::iter::range;
32043204
32053205
fn main() {
3206-
// range is imported by default
3206+
// `range` is imported by default
32073207
for _ in range(0, 10) {}
32083208
32093209
// Doesn't hinder you from importing it under a different name yourself

0 commit comments

Comments
 (0)