mirror of
https://github.com/rust-lang-cn/book-cn.git
synced 2025-02-02 23:38:41 +08:00
Update codes
This commit is contained in:
parent
a8739d9eb9
commit
44396e8d4b
@ -1,7 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "functions"
|
name = "functions"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Your Name <you@example.com>"]
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "branches"
|
name = "branches"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Your Name <you@example.com>"]
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "loops"
|
name = "loops"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Your Name <you@example.com>"]
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "loops"
|
name = "loops"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Your Name <you@example.com>"]
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "loops"
|
name = "loops"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Your Name <you@example.com>"]
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
let a = [10, 20, 30, 40, 50];
|
let a = [10, 20, 30, 40, 50];
|
||||||
|
|
||||||
for element in a.iter() {
|
for element in a {
|
||||||
println!("the value is: {}", element);
|
println!("the value is: {}", element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "variables"
|
name = "variables"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Your Name <you@example.com>"]
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -7,14 +7,10 @@ error[E0384]: cannot assign twice to immutable variable `x`
|
|||||||
| -
|
| -
|
||||||
| |
|
| |
|
||||||
| first assignment to `x`
|
| first assignment to `x`
|
||||||
| help: make this binding mutable: `mut x`
|
| help: consider making this binding mutable: `mut x`
|
||||||
3 | println!("The value of x is: {}", x);
|
3 | println!("The value of x is: {}", x);
|
||||||
4 | x = 6;
|
4 | x = 6;
|
||||||
| ^^^^^ cannot assign twice to immutable variable
|
| ^^^^^ cannot assign twice to immutable variable
|
||||||
|
|
||||||
error: aborting due to previous error
|
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0384`.
|
For more information about this error, try `rustc --explain E0384`.
|
||||||
error: could not compile `variables`
|
error: could not compile `variables` due to previous error
|
||||||
|
|
||||||
To learn more, run the command again with --verbose.
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "variables"
|
name = "variables"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Your Name <you@example.com>"]
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "variables"
|
name = "variables"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Your Name <you@example.com>"]
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -2,4 +2,5 @@ $ cargo run
|
|||||||
Compiling variables v0.1.0 (file:///projects/variables)
|
Compiling variables v0.1.0 (file:///projects/variables)
|
||||||
Finished dev [unoptimized + debuginfo] target(s) in 0.31s
|
Finished dev [unoptimized + debuginfo] target(s) in 0.31s
|
||||||
Running `target/debug/variables`
|
Running `target/debug/variables`
|
||||||
The value of x is: 12
|
The value of x in the inner scope is: 12
|
||||||
|
The value of x is: 6
|
||||||
|
@ -3,7 +3,10 @@ fn main() {
|
|||||||
|
|
||||||
let x = x + 1;
|
let x = x + 1;
|
||||||
|
|
||||||
let x = x * 2;
|
{
|
||||||
|
let x = x * 2;
|
||||||
|
println!("The value of x in the inner scope is: {}", x);
|
||||||
|
}
|
||||||
|
|
||||||
println!("The value of x is: {}", x);
|
println!("The value of x is: {}", x);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "variables"
|
name = "variables"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Your Name <you@example.com>"]
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "variables"
|
name = "variables"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Your Name <you@example.com>"]
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -6,9 +6,5 @@ error[E0308]: mismatched types
|
|||||||
3 | spaces = spaces.len();
|
3 | spaces = spaces.len();
|
||||||
| ^^^^^^^^^^^^ expected `&str`, found `usize`
|
| ^^^^^^^^^^^^ expected `&str`, found `usize`
|
||||||
|
|
||||||
error: aborting due to previous error
|
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0308`.
|
For more information about this error, try `rustc --explain E0308`.
|
||||||
error: could not compile `variables`
|
error: could not compile `variables` due to previous error
|
||||||
|
|
||||||
To learn more, run the command again with --verbose.
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "floating-point"
|
name = "floating-point"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Your Name <you@example.com>"]
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "numeric-operations"
|
name = "numeric-operations"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Your Name <you@example.com>"]
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -10,6 +10,7 @@ fn main() {
|
|||||||
|
|
||||||
// division
|
// division
|
||||||
let quotient = 56.7 / 32.2;
|
let quotient = 56.7 / 32.2;
|
||||||
|
let floored = 2 / 3; // Results in 0
|
||||||
|
|
||||||
// remainder
|
// remainder
|
||||||
let remainder = 43 % 5;
|
let remainder = 43 % 5;
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "boolean"
|
name = "boolean"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Your Name <you@example.com>"]
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
let t = true;
|
let t = true;
|
||||||
|
|
||||||
let f: bool = false; // 使用显式类型标注
|
let f: bool = false; // with explicit type annotation
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "char"
|
name = "char"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Your Name <you@example.com>"]
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "tuples"
|
name = "tuples"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Your Name <you@example.com>"]
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "tuples"
|
name = "tuples"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Your Name <you@example.com>"]
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "tuples"
|
name = "tuples"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Your Name <you@example.com>"]
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "arrays"
|
name = "arrays"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Your Name <you@example.com>"]
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "arrays"
|
name = "arrays"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Your Name <you@example.com>"]
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "arrays"
|
name = "arrays"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Your Name <you@example.com>"]
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "functions"
|
name = "functions"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Your Name <you@example.com>"]
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "functions"
|
name = "functions"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Your Name <you@example.com>"]
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "functions"
|
name = "functions"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Your Name <you@example.com>"]
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -2,5 +2,4 @@ $ cargo run
|
|||||||
Compiling functions v0.1.0 (file:///projects/functions)
|
Compiling functions v0.1.0 (file:///projects/functions)
|
||||||
Finished dev [unoptimized + debuginfo] target(s) in 0.31s
|
Finished dev [unoptimized + debuginfo] target(s) in 0.31s
|
||||||
Running `target/debug/functions`
|
Running `target/debug/functions`
|
||||||
The value of x is: 5
|
The measurement is: 5h
|
||||||
The value of y is: 6
|
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
another_function(5, 6);
|
print_labeled_measurement(5, 'h');
|
||||||
}
|
}
|
||||||
|
|
||||||
fn another_function(x: i32, y: i32) {
|
fn print_labeled_measurement(value: i32, unit_label: char) {
|
||||||
println!("The value of x is: {}", x);
|
println!("The measurement is: {}{}", value, unit_label);
|
||||||
println!("The value of y is: {}", y);
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "functions"
|
name = "functions"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Your Name <you@example.com>"]
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -25,9 +25,6 @@ warning: unnecessary parentheses around assigned value
|
|||||||
|
|
|
|
||||||
= note: `#[warn(unused_parens)]` on by default
|
= note: `#[warn(unused_parens)]` on by default
|
||||||
|
|
||||||
error: aborting due to 2 previous errors; 1 warning emitted
|
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0658`.
|
For more information about this error, try `rustc --explain E0658`.
|
||||||
error: could not compile `functions`
|
warning: `functions` (bin "functions") generated 1 warning
|
||||||
|
error: could not compile `functions` due to 2 previous errors; 1 warning emitted
|
||||||
To learn more, run the command again with --verbose.
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "functions"
|
name = "functions"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Your Name <you@example.com>"]
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
let x = 5;
|
|
||||||
|
|
||||||
let y = {
|
let y = {
|
||||||
let x = 3;
|
let x = 3;
|
||||||
x + 1
|
x + 1
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "functions"
|
name = "functions"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Your Name <you@example.com>"]
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "functions"
|
name = "functions"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Your Name <you@example.com>"]
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "functions"
|
name = "functions"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Your Name <you@example.com>"]
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -10,9 +10,5 @@ error[E0308]: mismatched types
|
|||||||
8 | x + 1;
|
8 | x + 1;
|
||||||
| - help: consider removing this semicolon
|
| - help: consider removing this semicolon
|
||||||
|
|
||||||
error: aborting due to previous error
|
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0308`.
|
For more information about this error, try `rustc --explain E0308`.
|
||||||
error: could not compile `functions`
|
error: could not compile `functions` due to previous error
|
||||||
|
|
||||||
To learn more, run the command again with --verbose.
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "comments"
|
name = "comments"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Your Name <you@example.com>"]
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
let lucky_number = 7; // 我感觉今天好幸运
|
let lucky_number = 7; // I’m feeling lucky today
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "comments"
|
name = "comments"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Your Name <you@example.com>"]
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
// 我感觉今天好幸运
|
// I’m feeling lucky today
|
||||||
let lucky_number = 7;
|
let lucky_number = 7;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "branches"
|
name = "branches"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Your Name <you@example.com>"]
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "branches"
|
name = "branches"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Your Name <you@example.com>"]
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "branches"
|
name = "branches"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Your Name <you@example.com>"]
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -6,9 +6,5 @@ error[E0308]: mismatched types
|
|||||||
4 | if number {
|
4 | if number {
|
||||||
| ^^^^^^ expected `bool`, found integer
|
| ^^^^^^ expected `bool`, found integer
|
||||||
|
|
||||||
error: aborting due to previous error
|
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0308`.
|
For more information about this error, try `rustc --explain E0308`.
|
||||||
error: could not compile `branches`
|
error: could not compile `branches` due to previous error
|
||||||
|
|
||||||
To learn more, run the command again with --verbose.
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "branches"
|
name = "branches"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Your Name <you@example.com>"]
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "branches"
|
name = "branches"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Your Name <you@example.com>"]
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "branches"
|
name = "branches"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Your Name <you@example.com>"]
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -8,9 +8,5 @@ error[E0308]: `if` and `else` have incompatible types
|
|||||||
| |
|
| |
|
||||||
| expected because of this
|
| expected because of this
|
||||||
|
|
||||||
error: aborting due to previous error
|
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0308`.
|
For more information about this error, try `rustc --explain E0308`.
|
||||||
error: could not compile `branches`
|
error: could not compile `branches` due to previous error
|
||||||
|
|
||||||
To learn more, run the command again with --verbose.
|
|
||||||
|
5
listings/ch03-common-programming-concepts/no-listing-32-5-loop-labels/Cargo.lock
generated
Normal file
5
listings/ch03-common-programming-concepts/no-listing-32-5-loop-labels/Cargo.lock
generated
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
[[package]]
|
||||||
|
name = "loops"
|
||||||
|
version = "0.1.0"
|
@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "loops"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
[dependencies]
|
@ -0,0 +1,13 @@
|
|||||||
|
$ cargo run
|
||||||
|
Compiling loops v0.1.0 (file:///projects/loops)
|
||||||
|
Finished dev [unoptimized + debuginfo] target(s) in 0.58s
|
||||||
|
Running `target/debug/loops`
|
||||||
|
count = 0
|
||||||
|
remaining = 10
|
||||||
|
remaining = 9
|
||||||
|
count = 1
|
||||||
|
remaining = 10
|
||||||
|
remaining = 9
|
||||||
|
count = 2
|
||||||
|
remaining = 10
|
||||||
|
End count = 2
|
@ -0,0 +1,21 @@
|
|||||||
|
fn main() {
|
||||||
|
let mut count = 0;
|
||||||
|
'counting_up: loop {
|
||||||
|
println!("count = {}", count);
|
||||||
|
let mut remaining = 10;
|
||||||
|
|
||||||
|
loop {
|
||||||
|
println!("remaining = {}", remaining);
|
||||||
|
if remaining == 9 {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if count == 2 {
|
||||||
|
break 'counting_up;
|
||||||
|
}
|
||||||
|
remaining -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
count += 1;
|
||||||
|
}
|
||||||
|
println!("End count = {}", count);
|
||||||
|
}
|
@ -1,7 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "loops"
|
name = "loops"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Your Name <you@example.com>"]
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "loops"
|
name = "loops"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Your Name <you@example.com>"]
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "loops"
|
name = "loops"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Your Name <you@example.com>"]
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "no_type_annotations"
|
name = "no_type_annotations"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Your Name <you@example.com>"]
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
@ -6,9 +6,5 @@ error[E0282]: type annotations needed
|
|||||||
2 | let guess = "42".parse().expect("Not a number!");
|
2 | let guess = "42".parse().expect("Not a number!");
|
||||||
| ^^^^^ consider giving `guess` a type
|
| ^^^^^ consider giving `guess` a type
|
||||||
|
|
||||||
error: aborting due to previous error
|
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0282`.
|
For more information about this error, try `rustc --explain E0282`.
|
||||||
error: could not compile `no_type_annotations`
|
error: could not compile `no_type_annotations` due to previous error
|
||||||
|
|
||||||
To learn more, run the command again with --verbose.
|
|
||||||
|
Loading…
Reference in New Issue
Block a user