Update codes

This commit is contained in:
Aaran Xu 2022-01-18 23:33:06 +08:00
parent a8739d9eb9
commit 44396e8d4b
61 changed files with 69 additions and 90 deletions

View File

@ -1,7 +1,6 @@
[package]
name = "functions"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
[dependencies]

View File

@ -1,7 +1,6 @@
[package]
name = "branches"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
[dependencies]

View File

@ -1,7 +1,6 @@
[package]
name = "loops"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
[dependencies]

View File

@ -1,7 +1,6 @@
[package]
name = "loops"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
[dependencies]

View File

@ -1,7 +1,6 @@
[package]
name = "loops"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
[dependencies]

View File

@ -1,7 +1,7 @@
fn main() {
let a = [10, 20, 30, 40, 50];
for element in a.iter() {
for element in a {
println!("the value is: {}", element);
}
}

View File

@ -1,7 +1,6 @@
[package]
name = "variables"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
[dependencies]

View File

@ -7,14 +7,10 @@ error[E0384]: cannot assign twice to immutable variable `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);
4 | x = 6;
| ^^^^^ cannot assign twice to immutable variable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0384`.
error: could not compile `variables`
To learn more, run the command again with --verbose.
error: could not compile `variables` due to previous error

View File

@ -1,7 +1,6 @@
[package]
name = "variables"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
[dependencies]

View File

@ -1,7 +1,6 @@
[package]
name = "variables"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
[dependencies]

View File

@ -2,4 +2,5 @@ $ cargo run
Compiling variables v0.1.0 (file:///projects/variables)
Finished dev [unoptimized + debuginfo] target(s) in 0.31s
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

View File

@ -3,7 +3,10 @@ fn main() {
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);
}

View File

@ -1,7 +1,6 @@
[package]
name = "variables"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
[dependencies]

View File

@ -1,7 +1,6 @@
[package]
name = "variables"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
[dependencies]

View File

@ -6,9 +6,5 @@ error[E0308]: mismatched types
3 | spaces = spaces.len();
| ^^^^^^^^^^^^ expected `&str`, found `usize`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.
error: could not compile `variables`
To learn more, run the command again with --verbose.
error: could not compile `variables` due to previous error

View File

@ -1,7 +1,6 @@
[package]
name = "floating-point"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
[dependencies]

View File

@ -1,7 +1,6 @@
[package]
name = "numeric-operations"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
[dependencies]

View File

@ -10,6 +10,7 @@ fn main() {
// division
let quotient = 56.7 / 32.2;
let floored = 2 / 3; // Results in 0
// remainder
let remainder = 43 % 5;

View File

@ -1,7 +1,6 @@
[package]
name = "boolean"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
[dependencies]

View File

@ -1,5 +1,5 @@
fn main() {
let t = true;
let f: bool = false; // 使用显式类型标注
let f: bool = false; // with explicit type annotation
}

View File

@ -1,7 +1,6 @@
[package]
name = "char"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
[dependencies]

View File

@ -1,7 +1,6 @@
[package]
name = "tuples"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
[dependencies]

View File

@ -1,7 +1,6 @@
[package]
name = "tuples"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
[dependencies]

View File

@ -1,7 +1,6 @@
[package]
name = "tuples"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
[dependencies]

View File

@ -1,7 +1,6 @@
[package]
name = "arrays"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
[dependencies]

View File

@ -1,7 +1,6 @@
[package]
name = "arrays"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
[dependencies]

View File

@ -1,7 +1,6 @@
[package]
name = "arrays"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
[dependencies]

View File

@ -1,7 +1,6 @@
[package]
name = "functions"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
[dependencies]

View File

@ -1,7 +1,6 @@
[package]
name = "functions"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
[dependencies]

View File

@ -1,7 +1,6 @@
[package]
name = "functions"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
[dependencies]

View File

@ -2,5 +2,4 @@ $ cargo run
Compiling functions v0.1.0 (file:///projects/functions)
Finished dev [unoptimized + debuginfo] target(s) in 0.31s
Running `target/debug/functions`
The value of x is: 5
The value of y is: 6
The measurement is: 5h

View File

@ -1,8 +1,7 @@
fn main() {
another_function(5, 6);
print_labeled_measurement(5, 'h');
}
fn another_function(x: i32, y: i32) {
println!("The value of x is: {}", x);
println!("The value of y is: {}", y);
fn print_labeled_measurement(value: i32, unit_label: char) {
println!("The measurement is: {}{}", value, unit_label);
}

View File

@ -1,7 +1,6 @@
[package]
name = "functions"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
[dependencies]

View File

@ -25,9 +25,6 @@ warning: unnecessary parentheses around assigned value
|
= 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`.
error: could not compile `functions`
To learn more, run the command again with --verbose.
warning: `functions` (bin "functions") generated 1 warning
error: could not compile `functions` due to 2 previous errors; 1 warning emitted

View File

@ -1,7 +1,6 @@
[package]
name = "functions"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
[dependencies]

View File

@ -1,6 +1,4 @@
fn main() {
let x = 5;
let y = {
let x = 3;
x + 1

View File

@ -1,7 +1,6 @@
[package]
name = "functions"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
[dependencies]

View File

@ -1,7 +1,6 @@
[package]
name = "functions"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
[dependencies]

View File

@ -1,7 +1,6 @@
[package]
name = "functions"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
[dependencies]

View File

@ -10,9 +10,5 @@ error[E0308]: mismatched types
8 | x + 1;
| - help: consider removing this semicolon
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.
error: could not compile `functions`
To learn more, run the command again with --verbose.
error: could not compile `functions` due to previous error

View File

@ -1,7 +1,6 @@
[package]
name = "comments"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
[dependencies]

View File

@ -1,3 +1,3 @@
fn main() {
let lucky_number = 7; // 我感觉今天好幸运
let lucky_number = 7; // Im feeling lucky today
}

View File

@ -1,7 +1,6 @@
[package]
name = "comments"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
[dependencies]

View File

@ -1,4 +1,4 @@
fn main() {
// 我感觉今天好幸运
// Im feeling lucky today
let lucky_number = 7;
}

View File

@ -1,7 +1,6 @@
[package]
name = "branches"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
[dependencies]

View File

@ -1,7 +1,6 @@
[package]
name = "branches"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
[dependencies]

View File

@ -1,7 +1,6 @@
[package]
name = "branches"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
[dependencies]

View File

@ -6,9 +6,5 @@ error[E0308]: mismatched types
4 | if number {
| ^^^^^^ expected `bool`, found integer
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.
error: could not compile `branches`
To learn more, run the command again with --verbose.
error: could not compile `branches` due to previous error

View File

@ -1,7 +1,6 @@
[package]
name = "branches"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
[dependencies]

View File

@ -1,7 +1,6 @@
[package]
name = "branches"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
[dependencies]

View File

@ -1,7 +1,6 @@
[package]
name = "branches"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
[dependencies]

View File

@ -8,9 +8,5 @@ error[E0308]: `if` and `else` have incompatible types
| |
| expected because of this
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.
error: could not compile `branches`
To learn more, run the command again with --verbose.
error: could not compile `branches` due to previous error

View 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"

View File

@ -0,0 +1,6 @@
[package]
name = "loops"
version = "0.1.0"
edition = "2018"
[dependencies]

View File

@ -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

View File

@ -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);
}

View File

@ -1,7 +1,6 @@
[package]
name = "loops"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
[dependencies]

View File

@ -1,7 +1,6 @@
[package]
name = "loops"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
[dependencies]

View File

@ -1,7 +1,6 @@
[package]
name = "loops"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
[dependencies]

View File

@ -1,7 +1,6 @@
[package]
name = "no_type_annotations"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -6,9 +6,5 @@ error[E0282]: type annotations needed
2 | let guess = "42".parse().expect("Not a number!");
| ^^^^^ consider giving `guess` a type
error: aborting due to previous error
For more information about this error, try `rustc --explain E0282`.
error: could not compile `no_type_annotations`
To learn more, run the command again with --verbose.
error: could not compile `no_type_annotations` due to previous error