This commit is contained in:
CelestialMelody 2022-07-01 17:42:18 +08:00
parent 5336805b74
commit 761945c40c
18 changed files with 118 additions and 12 deletions

View File

@ -0,0 +1,8 @@
# Intro
Rust uses the `print!` and `println!` macros to print text to the console.
## Further information
- [Hello World](https://doc.rust-lang.org/rust-by-example/hello.html)
- [Formatted print](https://doc.rust-lang.org/rust-by-example/hello/print.html)

View File

@ -0,0 +1,21 @@
// intro1.rs
// About this `I AM NOT DONE` thing:
// We sometimes encourage you to keep trying things on a given exercise, even
// after you already figured it out. If you got everything working and feel
// ready for the next exercise, remove the `I AM NOT DONE` comment below.
// Execute the command `rustlings hint intro1` for a hint.
fn main() {
println!("Hello and");
println!(r#" welcome to... "#);
println!(r#" _ _ _ "#);
println!(r#" _ __ _ _ ___| |_| (_)_ __ __ _ ___ "#);
println!(r#" | '__| | | / __| __| | | '_ \ / _` / __| "#);
println!(r#" | | | |_| \__ \ |_| | | | | | (_| \__ \ "#);
println!(r#" |_| \__,_|___/\__|_|_|_| |_|\__, |___/ "#);
println!(r#" |___/ "#);
println!();
println!("This exercise compiles successfully. The remaining exercises contain a compiler");
println!("or logic error. The central concept behind Rustlings is to fix these errors and");
println!("solve the exercises. Good luck!");
}

View File

@ -0,0 +1,7 @@
// intro2.rs
// Make the code print a greeting to the world.
// Execute `rustlings hint intro2` for a hint.
fn main() {
println!("Hello!");
}

2
I_have_done/intro/mod.rs Normal file
View File

@ -0,0 +1,2 @@
mod intro1;
mod intro2;

View File

@ -0,0 +1,9 @@
# Variables
In Rust, variables are immutable by default.
When a variable is immutable, once a value is bound to a name, you cant change that value.
You can make them mutable by adding mut in front of the variable name.
## Further information
- [Variables and Mutability](https://doc.rust-lang.org/book/ch03-01-variables-and-mutability.html)

View File

@ -0,0 +1,6 @@
mod variables1;
mod variables2;
mod variables3;
mod variables4;
mod variables5;
mod variables6;

View File

@ -0,0 +1,9 @@
// variables1.rs
// Make me compile!
// Execute the command `rustlings hint variables1` if you want a hint :)
fn main() {
let x = 5;
println!("x has the value {}", x);
}

View File

@ -0,0 +1,12 @@
// variables2.rs
// Make me compile! Execute the command `rustlings hint variables2` if you want a hint :)
fn main() {
let x = 10;
if x == 10 {
println!("Ten!");
} else {
println!("Not ten!");
}
}

View File

@ -0,0 +1,10 @@
// variables3.rs
// Make me compile! Execute the command `rustlings hint variables3` if you want a hint :)
fn main() {
let mut x = 3;
println!("Number {}", x);
x = 5; // don't change this line
println!("Number {}", x);
}

View File

@ -0,0 +1,8 @@
// variables4.rs
// Make me compile! Execute the command `rustlings hint variables4` if you want a hint :)
fn main() {
let x: i32 = 100;
println!("Number {}", x);
}

View File

@ -0,0 +1,10 @@
// variables5.rs
// Make me compile! Execute the command `rustlings hint variables5` if you want a hint :)
fn main() {
let number = "T-H-R-E-E"; // don't change this line
println!("Spell a Number : {}", number);
let mut number = 3;
println!("Number plus two is : {}", number + 2);
}

View File

@ -0,0 +1,9 @@
// variables6.rs
// Make me compile! Execute the command `rustlings hint variables6` if you want a hint :)
const NUMBER : i32 = 3;
fn main() {
println!("Number {}", NUMBER);
}

View File

@ -2,9 +2,8 @@
// Make me compile!
// Execute the command `rustlings hint variables1` if you want a hint :)
// I AM NOT DONE
fn main() {
x = 5;
let x = 5;
println!("x has the value {}", x);
}

View File

@ -1,10 +1,9 @@
// variables2.rs
// Make me compile! Execute the command `rustlings hint variables2` if you want a hint :)
// I AM NOT DONE
fn main() {
let x;
let x = 10;
if x == 10 {
println!("Ten!");
} else {

View File

@ -1,10 +1,9 @@
// variables3.rs
// Make me compile! Execute the command `rustlings hint variables3` if you want a hint :)
// I AM NOT DONE
fn main() {
let x = 3;
let mut x = 3;
println!("Number {}", x);
x = 5; // don't change this line
println!("Number {}", x);

View File

@ -1,9 +1,8 @@
// variables4.rs
// Make me compile! Execute the command `rustlings hint variables4` if you want a hint :)
// I AM NOT DONE
fn main() {
let x: i32;
let x: i32 = 100;
println!("Number {}", x);
}

View File

@ -1,11 +1,10 @@
// variables5.rs
// Make me compile! Execute the command `rustlings hint variables5` if you want a hint :)
// I AM NOT DONE
fn main() {
let number = "T-H-R-E-E"; // don't change this line
println!("Spell a Number : {}", number);
number = 3;
let mut number = 3;
println!("Number plus two is : {}", number + 2);
}

View File

@ -1,9 +1,9 @@
// variables6.rs
// Make me compile! Execute the command `rustlings hint variables6` if you want a hint :)
// I AM NOT DONE
const NUMBER = 3;
const NUMBER : i32 = 3;
fn main() {
println!("Number {}", NUMBER);
}