mirror of
https://github.com/rust-lang/book.git
synced 2026-11-30 19:34:32 -06:00
remove my home directory from path names
This commit is contained in:
@@ -149,7 +149,7 @@ run it:
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ cargo run
|
$ cargo run
|
||||||
Compiling functions v0.1.0 (file:///home/steve/tmp/functions)
|
Compiling functions v0.1.0 (file:///projects/functions)
|
||||||
Running `target/debug/functions`
|
Running `target/debug/functions`
|
||||||
thread ‘<main>’ panicked at ‘index out of bounds: the len is 5 but the index is 10’, src/main.rs:4
|
thread ‘<main>’ panicked at ‘index out of bounds: the len is 5 but the index is 10’, src/main.rs:4
|
||||||
Process didn’t exit successfully: `target/debug/functions` (exit code: 101)
|
Process didn’t exit successfully: `target/debug/functions` (exit code: 101)
|
||||||
@@ -186,7 +186,7 @@ fn main() {
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ cargo run
|
$ cargo run
|
||||||
Compiling functions v0.1.0 (file:///home/steve/tmp/functions)
|
Compiling functions v0.1.0 (file:///projects/functions)
|
||||||
src/main.rs:4:25: 4:26 error: the trait `core::fmt::Display` is not implemented for the type `[_; 5]` [E0277]
|
src/main.rs:4:25: 4:26 error: the trait `core::fmt::Display` is not implemented for the type `[_; 5]` [E0277]
|
||||||
src/main.rs:4 println!(“a is {}”, a);
|
src/main.rs:4 println!(“a is {}”, a);
|
||||||
^
|
^
|
||||||
@@ -225,7 +225,7 @@ This will work:
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ cargo run
|
$ cargo run
|
||||||
Compiling functions v0.1.0 (file:///home/steve/tmp/functions)
|
Compiling functions v0.1.0 (file:///projects/functions)
|
||||||
Running `target/debug/functions`
|
Running `target/debug/functions`
|
||||||
a is [1, 2, 3, 4, 5]
|
a is [1, 2, 3, 4, 5]
|
||||||
```
|
```
|
||||||
|
|||||||
+10
-10
@@ -46,7 +46,7 @@ Place the new example in `src/main.rs`, and run it:
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ cargo run
|
$ cargo run
|
||||||
Compiling functions v0.1.0 (file:///home/steve/tmp/functions)
|
Compiling functions v0.1.0 (file:///projects/functions)
|
||||||
Running `target/debug/functions`
|
Running `target/debug/functions`
|
||||||
Hello, world!
|
Hello, world!
|
||||||
Another function.
|
Another function.
|
||||||
@@ -74,7 +74,7 @@ Let’s try running it:
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ cargo run
|
$ cargo run
|
||||||
Compiling functions v0.1.0 (file:///home/steve/tmp/functions)
|
Compiling functions v0.1.0 (file:///projects/functions)
|
||||||
Running `target/debug/functions`
|
Running `target/debug/functions`
|
||||||
The value of x is: 5
|
The value of x is: 5
|
||||||
```
|
```
|
||||||
@@ -126,7 +126,7 @@ Let’s try it:
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ cargo run
|
$ cargo run
|
||||||
Compiling functions v0.1.0 (file:///home/steve/tmp/functions)
|
Compiling functions v0.1.0 (file:///projects/functions)
|
||||||
Running `target/debug/functions`
|
Running `target/debug/functions`
|
||||||
The value of x is: 5
|
The value of x is: 5
|
||||||
The value of y is: 6
|
The value of y is: 6
|
||||||
@@ -152,7 +152,7 @@ This has the same effect:
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ cargo run
|
$ cargo run
|
||||||
Compiling functions v0.1.0 (file:///home/steve/tmp/functions)
|
Compiling functions v0.1.0 (file:///projects/functions)
|
||||||
Running `target/debug/functions`
|
Running `target/debug/functions`
|
||||||
The value of x is: 5
|
The value of x is: 5
|
||||||
The value of y is: 6
|
The value of y is: 6
|
||||||
@@ -190,7 +190,7 @@ Let’s try running it:
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ cargo run
|
$ cargo run
|
||||||
Compiling functions v0.1.0 (file:///home/steve/tmp/functions)
|
Compiling functions v0.1.0 (file:///projects/functions)
|
||||||
Running `target/debug/functions`
|
Running `target/debug/functions`
|
||||||
The value of x is: 5
|
The value of x is: 5
|
||||||
```
|
```
|
||||||
@@ -264,7 +264,7 @@ If we try to run this program, we’ll get an error:
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ cargo run
|
$ cargo run
|
||||||
Compiling functions v0.1.0 (file:///home/steve/tmp/functions)
|
Compiling functions v0.1.0 (file:///projects/functions)
|
||||||
src/main.rs:2:14: 2:17 error: expected identifier, found keyword `let`
|
src/main.rs:2:14: 2:17 error: expected identifier, found keyword `let`
|
||||||
src/main.rs:2 let x = (let y = 6);
|
src/main.rs:2 let x = (let y = 6);
|
||||||
^~~
|
^~~
|
||||||
@@ -309,7 +309,7 @@ fn main() {
|
|||||||
Let’s try running this program:
|
Let’s try running this program:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
Compiling functions v0.1.0 (file:///home/steve/tmp/functions)
|
Compiling functions v0.1.0 (file:///projects/functions)
|
||||||
Running `target/debug/functions`
|
Running `target/debug/functions`
|
||||||
The value of y is: 11
|
The value of y is: 11
|
||||||
```
|
```
|
||||||
@@ -369,7 +369,7 @@ Running this gives:
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ cargo run
|
$ cargo run
|
||||||
Compiling functions v0.1.0 (file:///home/steve/tmp/functions)
|
Compiling functions v0.1.0 (file:///projects/functions)
|
||||||
Running `target/debug/functions`
|
Running `target/debug/functions`
|
||||||
The value of y is: 6
|
The value of y is: 6
|
||||||
The value of y is: 6
|
The value of y is: 6
|
||||||
@@ -413,7 +413,7 @@ Running this gives an error:
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ cargo run
|
$ cargo run
|
||||||
Compiling functions v0.1.0 (file:///home/steve/tmp/functions)
|
Compiling functions v0.1.0 (file:///projects/functions)
|
||||||
src/main.rs:7:1: 9:2 error: not all control paths return a value [E0269]
|
src/main.rs:7:1: 9:2 error: not all control paths return a value [E0269]
|
||||||
src/main.rs:7 fn plus_one(x: i32) -> i32 {
|
src/main.rs:7 fn plus_one(x: i32) -> i32 {
|
||||||
src/main.rs:8 x + 1;
|
src/main.rs:8 x + 1;
|
||||||
@@ -466,7 +466,7 @@ Running this will show us the values:
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ cargo run
|
$ cargo run
|
||||||
Compiling functions v0.1.0 (file:///home/steve/tmp/functions)
|
Compiling functions v0.1.0 (file:///projects/functions)
|
||||||
Running `target/debug/functions`
|
Running `target/debug/functions`
|
||||||
The value of x is: 5
|
The value of x is: 5
|
||||||
The value of y is: 6
|
The value of y is: 6
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ Let's try running it:
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ cargo run
|
$ cargo run
|
||||||
Compiling branches v0.1.0 (file:///home/steve/tmp/branches)
|
Compiling branches v0.1.0 (file:///projects/branches)
|
||||||
Running `target/debug/branches`
|
Running `target/debug/branches`
|
||||||
condition was true
|
condition was true
|
||||||
```
|
```
|
||||||
@@ -53,7 +53,7 @@ And then run it again:
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ cargo run
|
$ cargo run
|
||||||
Compiling branches v0.1.0 (file:///home/steve/tmp/branches)
|
Compiling branches v0.1.0 (file:///projects/branches)
|
||||||
Running `target/debug/branches`
|
Running `target/debug/branches`
|
||||||
condition was false
|
condition was false
|
||||||
```
|
```
|
||||||
@@ -92,7 +92,7 @@ fn main() {
|
|||||||
If we try to run this program, Rust will complain:
|
If we try to run this program, Rust will complain:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
Compiling branches v0.1.0 (file:///home/steve/tmp/branches)
|
Compiling branches v0.1.0 (file:///projects/branches)
|
||||||
src/main.rs:4:8: 4:17 error: mismatched types:
|
src/main.rs:4:8: 4:17 error: mismatched types:
|
||||||
expected `bool`,
|
expected `bool`,
|
||||||
found `_`
|
found `_`
|
||||||
@@ -131,7 +131,7 @@ Let's try running it:
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ cargo run
|
$ cargo run
|
||||||
Compiling branches v0.1.0 (file:///home/steve/tmp/branches)
|
Compiling branches v0.1.0 (file:///projects/branches)
|
||||||
Running `target/debug/branches`
|
Running `target/debug/branches`
|
||||||
condition was 5
|
condition was 5
|
||||||
```
|
```
|
||||||
@@ -166,7 +166,7 @@ Let’s run this:
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ cargo run
|
$ cargo run
|
||||||
Compiling branches v0.1.0 (file:///home/steve/tmp/branches)
|
Compiling branches v0.1.0 (file:///projects/branches)
|
||||||
Running `target/debug/branches`
|
Running `target/debug/branches`
|
||||||
The value of number is: 5
|
The value of number is: 5
|
||||||
```
|
```
|
||||||
@@ -195,7 +195,7 @@ fn main() {
|
|||||||
If we try to run this, we’ll get an error:
|
If we try to run this, we’ll get an error:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
Compiling branches v0.1.0 (file:///home/steve/tmp/branches)
|
Compiling branches v0.1.0 (file:///projects/branches)
|
||||||
src/main.rs:4:18: 8:6 error: if and else have incompatible types:
|
src/main.rs:4:18: 8:6 error: if and else have incompatible types:
|
||||||
expected `_`,
|
expected `_`,
|
||||||
found `&‘static str`
|
found `&‘static str`
|
||||||
|
|||||||
+4
-4
@@ -34,7 +34,7 @@ a keyboard shortcut, ‘control-c’, to stop a runaway program. Give it a try:
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ cargo run
|
$ cargo run
|
||||||
Compiling loops v0.1.0 (file:///home/steve/tmp/loops)
|
Compiling loops v0.1.0 (file:///projects/loops)
|
||||||
Running `target/debug/loops`
|
Running `target/debug/loops`
|
||||||
again!
|
again!
|
||||||
again!
|
again!
|
||||||
@@ -65,7 +65,7 @@ time:
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ cargo run
|
$ cargo run
|
||||||
Compiling loops v0.1.0 (file:///home/steve/tmp/loops)
|
Compiling loops v0.1.0 (file:///projects/loops)
|
||||||
Running `target/debug/loops`
|
Running `target/debug/loops`
|
||||||
once!
|
once!
|
||||||
```
|
```
|
||||||
@@ -99,7 +99,7 @@ fn main() {
|
|||||||
If we run this, we’ll get some output:
|
If we run this, we’ll get some output:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
Compiling loops v0.1.0 (file:///home/steve/tmp/loops)
|
Compiling loops v0.1.0 (file:///projects/loops)
|
||||||
Running `target/debug/loops`
|
Running `target/debug/loops`
|
||||||
3!
|
3!
|
||||||
2!
|
2!
|
||||||
@@ -162,7 +162,7 @@ Running this will print out every element of the array:
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ cargo run
|
$ cargo run
|
||||||
Compiling loops v0.1.0 (file:///home/steve/tmp/loops)
|
Compiling loops v0.1.0 (file:///projects/loops)
|
||||||
Running `target/debug/loops`
|
Running `target/debug/loops`
|
||||||
the value is: 1
|
the value is: 1
|
||||||
the value is: 2
|
the value is: 2
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ Let’s try running it:
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ cargo run
|
$ cargo run
|
||||||
Compiling functions v0.1.0 (file:///home/steve/tmp/functions)
|
Compiling functions v0.1.0 (file:///projects/functions)
|
||||||
Running `target/debug/functions`
|
Running `target/debug/functions`
|
||||||
The value of s is: [1, 2]
|
The value of s is: [1, 2]
|
||||||
```
|
```
|
||||||
|
|||||||
+1
-1
@@ -45,7 +45,7 @@ Let's try running this program with `cargo run`:
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ cargo run
|
$ cargo run
|
||||||
Compiling points v0.1.0 (file:///home/steve/tmp/points)
|
Compiling points v0.1.0 (file:///projects/points)
|
||||||
Running `target/debug/points`
|
Running `target/debug/points`
|
||||||
Point 1: (0, 5)
|
Point 1: (0, 5)
|
||||||
Point 2: (12, 0)
|
Point 2: (12, 0)
|
||||||
|
|||||||
+2
-2
@@ -96,7 +96,7 @@ test it_works ... FAILED
|
|||||||
failures:
|
failures:
|
||||||
|
|
||||||
---- it_works stdout ----
|
---- it_works stdout ----
|
||||||
thread 'it_works' panicked at 'assertion failed: false', /home/steve/tmp/adder/src/lib.rs:3
|
thread 'it_works' panicked at 'assertion failed: false', /projects/adder/src/lib.rs:3
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -473,7 +473,7 @@ Let's run the tests again:
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ cargo test
|
$ cargo test
|
||||||
Compiling adder v0.0.1 (file:///home/steve/tmp/adder)
|
Compiling adder v0.0.1 (file:///projects/adder)
|
||||||
Running target/adder-91b3e234d4ed382a
|
Running target/adder-91b3e234d4ed382a
|
||||||
|
|
||||||
running 1 test
|
running 1 test
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ Let’s build the project now:
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ cargo build --release
|
$ cargo build --release
|
||||||
Compiling embed v0.1.0 (file:///home/steve/src/embed)
|
Compiling embed v0.1.0 (file:///projects/embed)
|
||||||
```
|
```
|
||||||
|
|
||||||
We’ve chosen `cargo build --release`, which builds with optimizations on. We
|
We’ve chosen `cargo build --release`, which builds with optimizations on. We
|
||||||
|
|||||||
+10
-10
@@ -38,7 +38,7 @@ And finally, run it:
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ cargo run
|
$ cargo run
|
||||||
Compiling bindings v0.1.0 (file:///home/steve/tmp/bindings)
|
Compiling bindings v0.1.0 (file:///projects/bindings)
|
||||||
Running `target/debug/bindings`
|
Running `target/debug/bindings`
|
||||||
The value of x is: 5
|
The value of x is: 5
|
||||||
```
|
```
|
||||||
@@ -142,7 +142,7 @@ And run it with `cargo run`:
|
|||||||
|
|
||||||
```text
|
```text
|
||||||
$ cargo run
|
$ cargo run
|
||||||
Compiling bindings v0.1.0 (file:///home/steve/tmp/bindings)
|
Compiling bindings v0.1.0 (file:///projects/bindings)
|
||||||
Running `target/debug/bindings`
|
Running `target/debug/bindings`
|
||||||
The value of x is: 5
|
The value of x is: 5
|
||||||
The value of y is: 6
|
The value of y is: 6
|
||||||
@@ -242,7 +242,7 @@ And run it with `cargo run`:
|
|||||||
|
|
||||||
```text
|
```text
|
||||||
$ cargo run
|
$ cargo run
|
||||||
Compiling bindings v0.1.0 (file:///home/steve/tmp/bindings)
|
Compiling bindings v0.1.0 (file:///projects/bindings)
|
||||||
Running `target/debug/bindings`
|
Running `target/debug/bindings`
|
||||||
The value of x is: 5
|
The value of x is: 5
|
||||||
```
|
```
|
||||||
@@ -264,7 +264,7 @@ fn main() {
|
|||||||
We can find out the answer with `cargo run`:
|
We can find out the answer with `cargo run`:
|
||||||
|
|
||||||
```text
|
```text
|
||||||
Compiling bindings v0.1.0 (file:///home/steve/tmp/bindings)
|
Compiling bindings v0.1.0 (file:///projects/bindings)
|
||||||
src/main.rs:4:39: 4:40 error: use of possibly uninitialized variable: `x` [E0381]
|
src/main.rs:4:39: 4:40 error: use of possibly uninitialized variable: `x` [E0381]
|
||||||
src/main.rs:4 println!(“The value of x is: {}”, x);
|
src/main.rs:4 println!(“The value of x is: {}”, x);
|
||||||
^
|
^
|
||||||
@@ -334,7 +334,7 @@ fn main() {
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ cargo run
|
$ cargo run
|
||||||
Compiling bindings v0.1.0 (file:///home/steve/tmp/bindings)
|
Compiling bindings v0.1.0 (file:///projects/bindings)
|
||||||
src/main.rs:4:5: 4:10 error: re-assignment of immutable variable `x` [E0384]
|
src/main.rs:4:5: 4:10 error: re-assignment of immutable variable `x` [E0384]
|
||||||
src/main.rs:4 x = 6;
|
src/main.rs:4 x = 6;
|
||||||
^~~~~
|
^~~~~
|
||||||
@@ -365,7 +365,7 @@ Running this, we get:
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ cargo run
|
$ cargo run
|
||||||
Compiling bindings v0.1.0 (file:///home/steve/tmp/bindings)
|
Compiling bindings v0.1.0 (file:///projects/bindings)
|
||||||
Running `target/debug/bindings`
|
Running `target/debug/bindings`
|
||||||
The value of x is: 5
|
The value of x is: 5
|
||||||
The value of x is: 6
|
The value of x is: 6
|
||||||
@@ -389,7 +389,7 @@ The compiler will complain about this program:
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ cargo build
|
$ cargo build
|
||||||
Compiling bindings v0.1.0 (file:///home/steve/tmp/bindings)
|
Compiling bindings v0.1.0 (file:///projects/bindings)
|
||||||
src/main.rs:5:5: 5:10 error: re-assignment of immutable variable `y` [E0384]
|
src/main.rs:5:5: 5:10 error: re-assignment of immutable variable `y` [E0384]
|
||||||
src/main.rs:5 y = 8;
|
src/main.rs:5 y = 8;
|
||||||
^~~~~
|
^~~~~
|
||||||
@@ -517,7 +517,7 @@ fn main() {
|
|||||||
This will print:
|
This will print:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
Compiling bindings v0.1.0 (file:///home/steve/tmp/bindings)
|
Compiling bindings v0.1.0 (file:///projects/bindings)
|
||||||
Running `target/debug/bindings`
|
Running `target/debug/bindings`
|
||||||
The value of x is: 12
|
The value of x is: 12
|
||||||
```
|
```
|
||||||
@@ -562,7 +562,7 @@ If we try to compile, we get an error:
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ cargo build
|
$ cargo build
|
||||||
Compiling bindings v0.1.0 (file:///home/steve/tmp/bindings)
|
Compiling bindings v0.1.0 (file:///projects/bindings)
|
||||||
src/main.rs:8:5: 8:11 error: re-assignment of immutable variable `x` [E0384]
|
src/main.rs:8:5: 8:11 error: re-assignment of immutable variable `x` [E0384]
|
||||||
src/main.rs:8 x = 15;
|
src/main.rs:8 x = 15;
|
||||||
^~~~~~
|
^~~~~~
|
||||||
@@ -630,7 +630,7 @@ If we run this example, we can see the shadow appear and disappear:
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ cargo run
|
$ cargo run
|
||||||
Compiling bindings v0.1.0 (file:///home/steve/tmp/bindings)
|
Compiling bindings v0.1.0 (file:///projects/bindings)
|
||||||
Running `target/debug/bindings`
|
Running `target/debug/bindings`
|
||||||
Before shadowing, x is: 5
|
Before shadowing, x is: 5
|
||||||
Now that x is shadowed, x is: 6
|
Now that x is shadowed, x is: 6
|
||||||
|
|||||||
Reference in New Issue
Block a user