mirror of
https://github.com/rust-lang/book.git
synced 2026-11-30 19:24:32 -06:00
Merge pull request #78 from Mark-Simulacrum/remove-space
Remove trailing spaces from all src files.
This commit is contained in:
@@ -110,7 +110,7 @@ fn main() {
|
||||
let mut a = [1, 2, 3, 4, 5];
|
||||
|
||||
let first = a[0];
|
||||
|
||||
|
||||
a[0] = 7;
|
||||
|
||||
println!("The value of first is: {}", first);
|
||||
|
||||
+1
-1
@@ -298,7 +298,7 @@ fn main() {
|
||||
|
||||
let y = {
|
||||
let z = 1;
|
||||
|
||||
|
||||
x + z + 5
|
||||
};
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ fn main() {
|
||||
} else {
|
||||
println!("condition was false");
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Let's try running it:
|
||||
@@ -160,7 +160,7 @@ fn main() {
|
||||
|
||||
println!("The value of number is: {}", number);
|
||||
}
|
||||
```
|
||||
```
|
||||
|
||||
Let’s run this:
|
||||
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ not want the script to run ‘sudo’ then pass it the --disable-sudo flag.
|
||||
You may uninstall later by running /usr/local/lib/rustlib/uninstall.sh,
|
||||
or by running this script again with the --uninstall flag.
|
||||
|
||||
Continue? (y/N)
|
||||
Continue? (y/N)
|
||||
```
|
||||
|
||||
From here, press `y` for ‘yes’, and then follow the rest of the prompts.
|
||||
|
||||
+2
-2
@@ -184,7 +184,7 @@ Instead, we can use our last kind of loop: the `for` loop. It looks like this:
|
||||
fn main() {
|
||||
let a = [1, 2, 3, 4, 5];
|
||||
let mut index = 0;
|
||||
|
||||
|
||||
for element in a.iter() {
|
||||
println!("the value is: {}", element);
|
||||
}
|
||||
@@ -193,6 +193,6 @@ fn main() {
|
||||
|
||||
** NOTE: see [https://github.com/rust-lang/rust/issues/25725#issuecomment-166365658](https://github.com/rust-lang/rust/issues/25725#issuecomment-166365658), we may want to change this **
|
||||
|
||||
If we run this, we'll see the same output as the previous example.
|
||||
If we run this, we'll see the same output as the previous example.
|
||||
|
||||
** I'm going to leave it at this for now until we decide how we want to do it**
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
Rust’s central feature is called ‘ownership’. It is a feature that is
|
||||
straightforward to explain, but has deep implications for the rest of the
|
||||
language.
|
||||
language.
|
||||
|
||||
Rust is committed to both safety and speed. One of the key tools for balancing
|
||||
between them is “zero-cost abstractions”: the various abstractions in Rust do
|
||||
|
||||
@@ -54,7 +54,7 @@ Let’s take a closer look at the function call here:
|
||||
```rust
|
||||
# fn calculate_length(s: &String) -> usize {
|
||||
# let length = s.len();
|
||||
#
|
||||
#
|
||||
# length
|
||||
# }
|
||||
let s1 = String::from("hello");
|
||||
|
||||
+6
-6
@@ -78,13 +78,13 @@ that it will still be valid in the future. Consider this:
|
||||
```rust
|
||||
# fn first_word(s: &String) -> usize {
|
||||
# let bytes = s.as_bytes();
|
||||
#
|
||||
#
|
||||
# for (i, &byte) in bytes.iter().enumerate() {
|
||||
# if byte == 32 {
|
||||
# return i;
|
||||
# }
|
||||
# }
|
||||
#
|
||||
#
|
||||
# s.len()
|
||||
# }
|
||||
|
||||
@@ -186,13 +186,13 @@ the slice version of `first_word()` will throw an error:
|
||||
```rust,ignore
|
||||
# fn first_word(s: &String) -> &str {
|
||||
# let bytes = s.as_bytes();
|
||||
#
|
||||
#
|
||||
# for (i, &byte) in bytes.iter().enumerate() {
|
||||
# if byte == 32 {
|
||||
# return &s[0..i];
|
||||
# }
|
||||
# }
|
||||
#
|
||||
#
|
||||
# &s[..]
|
||||
# }
|
||||
fn main() {
|
||||
@@ -266,13 +266,13 @@ with no loss of functionality:
|
||||
```rust
|
||||
# fn first_word(s: &str) -> &str {
|
||||
# let bytes = s.as_bytes();
|
||||
#
|
||||
#
|
||||
# for (i, &byte) in bytes.iter().enumerate() {
|
||||
# if byte == 32 {
|
||||
# return &s[0..i];
|
||||
# }
|
||||
# }
|
||||
#
|
||||
#
|
||||
# &s[..]
|
||||
# }
|
||||
fn main() {
|
||||
|
||||
+3
-3
@@ -23,11 +23,11 @@ fn main() {
|
||||
let x1 = 0.0;
|
||||
let y1 = 5.0;
|
||||
|
||||
let x2 = 12.0;
|
||||
let x2 = 12.0;
|
||||
let y2 = 0.0;
|
||||
|
||||
|
||||
let answer = distance(x1, y1, x2, y2);
|
||||
|
||||
|
||||
println!("Point 1: ({}, {})", x1, y1);
|
||||
println!("Point 2: ({}, {})", x2, y2);
|
||||
println!("Distance: {}", answer);
|
||||
|
||||
@@ -437,8 +437,8 @@ fn main() {
|
||||
let x = 5;
|
||||
println!("x is now in scope");
|
||||
|
||||
println!("In real code, we’d now do a bunch of work.");
|
||||
|
||||
println!("In real code, we’d now do a bunch of work.");
|
||||
|
||||
println!("x will go out of scope now! The next curly brace is ending the main function.");
|
||||
}
|
||||
```
|
||||
@@ -464,7 +464,7 @@ fn main() {
|
||||
}
|
||||
|
||||
println!("x is still in scope, but y is now out of scope and is not usable");
|
||||
|
||||
|
||||
println!("x will go out of scope now! The next curly brace is ending the main function.");
|
||||
}
|
||||
```
|
||||
@@ -483,7 +483,7 @@ fn main() {
|
||||
let x = 6;
|
||||
|
||||
println!("The value of x is: {}", x);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Running it, we can see the shadowing in action:
|
||||
|
||||
Reference in New Issue
Block a user