mirror of
https://github.com/rust-lang/rustlings.git
synced 2025-01-09 20:03:24 +03:00
Compare commits
2 commits
cf3f6fd6a1
...
0f4c42d54e
Author | SHA1 | Date | |
---|---|---|---|
0f4c42d54e | |||
bde2524c3b |
74
Cargo.lock
generated
74
Cargo.lock
generated
|
@ -80,9 +80,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anyhow"
|
name = "anyhow"
|
||||||
version = "1.0.83"
|
version = "1.0.86"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "25bdb32cbbdce2b519a9cd7df3a678443100e265d5e25ca763b7572a5104f5f3"
|
checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "assert_cmd"
|
name = "assert_cmd"
|
||||||
|
@ -210,18 +210,18 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crossbeam-channel"
|
name = "crossbeam-channel"
|
||||||
version = "0.5.12"
|
version = "0.5.13"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ab3db02a9c5b5121e1e42fbdb1aeb65f5e02624cc58c43f2884c6ccac0b82f95"
|
checksum = "33480d6946193aa8033910124896ca395333cae7e2d1113d1fef6c3272217df2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"crossbeam-utils",
|
"crossbeam-utils",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crossbeam-utils"
|
name = "crossbeam-utils"
|
||||||
version = "0.8.19"
|
version = "0.8.20"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345"
|
checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crossterm"
|
name = "crossterm"
|
||||||
|
@ -262,9 +262,9 @@ checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "either"
|
name = "either"
|
||||||
version = "1.11.0"
|
version = "1.12.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a47c1c47d2f5964e29c61246e81db715514cd532db6b5116a25ea3c03d6780a2"
|
checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "equivalent"
|
name = "equivalent"
|
||||||
|
@ -334,12 +334,6 @@ dependencies = [
|
||||||
"hashbrown",
|
"hashbrown",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "indoc"
|
|
||||||
version = "2.0.5"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "b248f5224d1d606005e02c97f5aa4e88eeb230488bcc03bc9ca4d7991399f2b5"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "inotify"
|
name = "inotify"
|
||||||
version = "0.9.6"
|
version = "0.9.6"
|
||||||
|
@ -403,9 +397,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.154"
|
version = "0.2.155"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346"
|
checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lock_api"
|
name = "lock_api"
|
||||||
|
@ -571,9 +565,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.82"
|
version = "1.0.83"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b"
|
checksum = "0b33eb56c327dec362a9e55b3ad14f9d2f0904fb5a5b03b513ab5465399e9f43"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
|
@ -589,21 +583,21 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ratatui"
|
name = "ratatui"
|
||||||
version = "0.26.2"
|
version = "0.26.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a564a852040e82671dc50a37d88f3aa83bbc690dfc6844cfe7a2591620206a80"
|
checksum = "f44c9e68fd46eda15c646fbb85e1040b657a58cdc8c98db1d97a55930d991eef"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.5.0",
|
"bitflags 2.5.0",
|
||||||
"cassowary",
|
"cassowary",
|
||||||
"compact_str",
|
"compact_str",
|
||||||
"crossterm",
|
"crossterm",
|
||||||
"indoc",
|
|
||||||
"itertools",
|
"itertools",
|
||||||
"lru",
|
"lru",
|
||||||
"paste",
|
"paste",
|
||||||
"stability",
|
"stability",
|
||||||
"strum",
|
"strum",
|
||||||
"unicode-segmentation",
|
"unicode-segmentation",
|
||||||
|
"unicode-truncate",
|
||||||
"unicode-width",
|
"unicode-width",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -684,9 +678,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustversion"
|
name = "rustversion"
|
||||||
version = "1.0.16"
|
version = "1.0.17"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "092474d1a01ea8278f69e6a358998405fae5b8b963ddaeb2b0b04a128bf1dfb0"
|
checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ryu"
|
name = "ryu"
|
||||||
|
@ -711,18 +705,18 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.201"
|
version = "1.0.202"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "780f1cebed1629e4753a1a38a3c72d30b97ec044f0aef68cb26650a3c5cf363c"
|
checksum = "226b61a0d411b2ba5ff6d7f73a476ac4f8bb900373459cd00fab8512828ba395"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "1.0.201"
|
version = "1.0.202"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c5e405930b9796f1c00bee880d03fc7e0bb4b9a11afc776885ffe84320da2865"
|
checksum = "6048858004bcff69094cd972ed40a32500f153bd3be9f716b2eed2e8217c4838"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
@ -742,9 +736,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_spanned"
|
name = "serde_spanned"
|
||||||
version = "0.6.5"
|
version = "0.6.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1"
|
checksum = "79e674e01f999af37c49f70a6ede167a8a60b2503e56c5599532a65baa5969a0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
@ -831,9 +825,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "2.0.63"
|
version = "2.0.65"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704"
|
checksum = "d2863d96a84c6439701d7a38f9de935ec562c8832cc55d1dde0f513b52fad106"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
@ -848,18 +842,18 @@ checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "toml_datetime"
|
name = "toml_datetime"
|
||||||
version = "0.6.5"
|
version = "0.6.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1"
|
checksum = "4badfd56924ae69bcc9039335b2e017639ce3f9b001c393c1b2d1ef846ce2cbf"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "toml_edit"
|
name = "toml_edit"
|
||||||
version = "0.22.12"
|
version = "0.22.13"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d3328d4f68a705b2a4498da1d580585d39a6510f98318a2cec3018a7ec61ddef"
|
checksum = "c127785850e8c20836d49732ae6abfa47616e60bf9d9f57c43c250361a9db96c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"indexmap",
|
"indexmap",
|
||||||
"serde",
|
"serde",
|
||||||
|
@ -880,6 +874,16 @@ version = "1.11.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202"
|
checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-truncate"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5a5fbabedabe362c618c714dbefda9927b5afc8e2a8102f47f081089a9019226"
|
||||||
|
dependencies = [
|
||||||
|
"itertools",
|
||||||
|
"unicode-width",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-width"
|
name = "unicode-width"
|
||||||
version = "0.1.12"
|
version = "0.1.12"
|
||||||
|
|
|
@ -20,8 +20,8 @@ license = "MIT"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
serde = { version = "1.0.199", features = ["derive"] }
|
serde = { version = "1.0.202", features = ["derive"] }
|
||||||
toml_edit = { version = "0.22.12", default-features = false, features = ["parse", "serde"] }
|
toml_edit = { version = "0.22.13", default-features = false, features = ["parse", "serde"] }
|
||||||
|
|
||||||
[package]
|
[package]
|
||||||
name = "rustlings"
|
name = "rustlings"
|
||||||
|
@ -46,13 +46,13 @@ include = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.83"
|
anyhow = "1.0.86"
|
||||||
clap = { version = "4.5.4", features = ["derive"] }
|
clap = { version = "4.5.4", features = ["derive"] }
|
||||||
crossterm = "0.27.0"
|
crossterm = "0.27.0"
|
||||||
hashbrown = "0.14.5"
|
hashbrown = "0.14.5"
|
||||||
notify-debouncer-mini = { version = "0.4.1", default-features = false }
|
notify-debouncer-mini = { version = "0.4.1", default-features = false }
|
||||||
os_pipe = "1.1.5"
|
os_pipe = "1.1.5"
|
||||||
ratatui = { version = "0.26.2", default-features = false, features = ["crossterm"] }
|
ratatui = { version = "0.26.3", default-features = false, features = ["crossterm"] }
|
||||||
rustlings-macros = { path = "rustlings-macros", version = "=6.0.0-beta.9" }
|
rustlings-macros = { path = "rustlings-macros", version = "=6.0.0-beta.9" }
|
||||||
serde_json = "1.0.117"
|
serde_json = "1.0.117"
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// Make the code print a greeting to the world.
|
// TODO: Fix the code to print "Hello world!".
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
printline!("Hello there!")
|
printline!("Hello world!");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Make me compile!
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
// TODO: Add missing keyword.
|
||||||
x = 5;
|
x = 5;
|
||||||
println!("x has the value {}", x);
|
|
||||||
|
println!("x has the value {x}");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
fn main() {
|
fn main() {
|
||||||
|
// TODO: Change the line below to fix the compiler error.
|
||||||
let x;
|
let x;
|
||||||
|
|
||||||
if x == 10 {
|
if x == 10 {
|
||||||
println!("x is ten!");
|
println!("x is ten!");
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
fn main() {
|
fn main() {
|
||||||
|
// TODO: Change the line below to fix the compiler error.
|
||||||
let x: i32;
|
let x: i32;
|
||||||
println!("Number {}", x);
|
|
||||||
|
println!("Number {x}");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
|
// TODO: Fix the compiler error.
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let x = 3;
|
let x = 3;
|
||||||
println!("Number {}", x);
|
println!("Number {x}");
|
||||||
x = 5; // don't change this line
|
|
||||||
println!("Number {}", x);
|
x = 5; // Don't change this line
|
||||||
|
println!("Number {x}");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
fn main() {
|
fn main() {
|
||||||
let number = "T-H-R-E-E"; // don't change this line
|
let number = "T-H-R-E-E"; // Don't change this line
|
||||||
println!("Spell a Number : {}", number);
|
println!("Spell a number: {}", number);
|
||||||
number = 3; // don't rename this variable
|
|
||||||
println!("Number plus two is : {}", number + 2);
|
// TODO: Fix the compiler error by changing the line below without renaming the the variable.
|
||||||
|
number = 3;
|
||||||
|
println!("Number plus two is: {}", number + 2);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
|
// TODO: Change the line below to fix the compiler error.
|
||||||
const NUMBER = 3;
|
const NUMBER = 3;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("Number {}", NUMBER);
|
println!("Number: {NUMBER}");
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,20 +29,21 @@ https://github.com/rust-lang/rustlings/blob/main/CONTRIBUTING.md
|
||||||
|
|
||||||
# INTRO
|
# INTRO
|
||||||
|
|
||||||
# TODO: Update exercise
|
|
||||||
[[exercises]]
|
[[exercises]]
|
||||||
name = "intro1"
|
name = "intro1"
|
||||||
dir = "00_intro"
|
dir = "00_intro"
|
||||||
test = false
|
test = false
|
||||||
# TODO: Fix hint
|
hint = """
|
||||||
hint = """Enter `n` to move on to the next exercise. You might need to press ENTER after typing `n`."""
|
Enter `n` to move on to the next exercise.
|
||||||
|
You might need to press ENTER after typing `n`."""
|
||||||
|
|
||||||
[[exercises]]
|
[[exercises]]
|
||||||
name = "intro2"
|
name = "intro2"
|
||||||
dir = "00_intro"
|
dir = "00_intro"
|
||||||
test = false
|
test = false
|
||||||
hint = """
|
hint = """
|
||||||
The compiler is informing us that we've got the name of the print macro wrong, and has suggested an alternative."""
|
The compiler is informing us that we've got the name of the print macro wrong.
|
||||||
|
It also suggests an alternative."""
|
||||||
|
|
||||||
# VARIABLES
|
# VARIABLES
|
||||||
|
|
||||||
|
@ -51,18 +52,18 @@ name = "variables1"
|
||||||
dir = "01_variables"
|
dir = "01_variables"
|
||||||
test = false
|
test = false
|
||||||
hint = """
|
hint = """
|
||||||
The declaration in the first line in the main function is missing a keyword
|
The declaration in the `main` function is missing a keyword that is needed
|
||||||
that is needed in Rust to create a new variable binding."""
|
in Rust to create a new variable binding."""
|
||||||
|
|
||||||
[[exercises]]
|
[[exercises]]
|
||||||
name = "variables2"
|
name = "variables2"
|
||||||
dir = "01_variables"
|
dir = "01_variables"
|
||||||
test = false
|
test = false
|
||||||
hint = """
|
hint = """
|
||||||
The compiler message is saying that Rust cannot infer the type that the
|
The compiler message is saying that Rust can't infer the type that the
|
||||||
variable binding `x` has with what is given here.
|
variable binding `x` has with what is given here.
|
||||||
|
|
||||||
What happens if you annotate the first line in the main function with a type
|
What happens if you annotate the first line in the `main` function with a type
|
||||||
annotation?
|
annotation?
|
||||||
|
|
||||||
What if you give `x` a value?
|
What if you give `x` a value?
|
||||||
|
@ -78,9 +79,9 @@ name = "variables3"
|
||||||
dir = "01_variables"
|
dir = "01_variables"
|
||||||
test = false
|
test = false
|
||||||
hint = """
|
hint = """
|
||||||
Oops! In this exercise, we have a variable binding that we've created on in the
|
In this exercise, we have a variable binding that we've created in the `main`
|
||||||
first line in the `main` function, and we're trying to use it in the next line,
|
function, and we're trying to use it in the next line, but we haven't given it
|
||||||
but we haven't given it a value.
|
a value.
|
||||||
|
|
||||||
We can't print out something that isn't there; try giving `x` a value!
|
We can't print out something that isn't there; try giving `x` a value!
|
||||||
|
|
||||||
|
@ -92,7 +93,7 @@ name = "variables4"
|
||||||
dir = "01_variables"
|
dir = "01_variables"
|
||||||
test = false
|
test = false
|
||||||
hint = """
|
hint = """
|
||||||
In Rust, variable bindings are immutable by default. But here we're trying
|
In Rust, variable bindings are immutable by default. But here, we're trying
|
||||||
to reassign a different value to `x`! There's a keyword we can use to make
|
to reassign a different value to `x`! There's a keyword we can use to make
|
||||||
a variable binding mutable instead."""
|
a variable binding mutable instead."""
|
||||||
|
|
||||||
|
@ -120,12 +121,12 @@ dir = "01_variables"
|
||||||
test = false
|
test = false
|
||||||
hint = """
|
hint = """
|
||||||
We know about variables and mutability, but there is another important type of
|
We know about variables and mutability, but there is another important type of
|
||||||
variable available: constants.
|
variables available: constants.
|
||||||
|
|
||||||
Constants are always immutable and they are declared with keyword `const` rather
|
Constants are always immutable. They are declared with the keyword `const` instead
|
||||||
than keyword `let`.
|
of `let`.
|
||||||
|
|
||||||
Constants types must also always be annotated.
|
The type of Constants must always be annotated.
|
||||||
|
|
||||||
Read more about constants and the differences between variables and constants
|
Read more about constants and the differences between variables and constants
|
||||||
under 'Constants' in the book's section 'Variables and Mutability':
|
under 'Constants' in the book's section 'Variables and Mutability':
|
||||||
|
@ -139,7 +140,7 @@ name = "functions1"
|
||||||
dir = "02_functions"
|
dir = "02_functions"
|
||||||
test = false
|
test = false
|
||||||
hint = """
|
hint = """
|
||||||
This main function is calling a function that it expects to exist, but the
|
This `main` function is calling a function that it expects to exist, but the
|
||||||
function doesn't exist. It expects this function to have the name `call_me`.
|
function doesn't exist. It expects this function to have the name `call_me`.
|
||||||
It expects this function to not take any arguments and not return a value.
|
It expects this function to not take any arguments and not return a value.
|
||||||
Sounds a lot like `main`, doesn't it?"""
|
Sounds a lot like `main`, doesn't it?"""
|
||||||
|
@ -688,7 +689,7 @@ test = false
|
||||||
hint = """
|
hint = """
|
||||||
If other functions can return a `Result`, why shouldn't `main`? It's a fairly
|
If other functions can return a `Result`, why shouldn't `main`? It's a fairly
|
||||||
common convention to return something like `Result<(), ErrorType>` from your
|
common convention to return something like `Result<(), ErrorType>` from your
|
||||||
main function.
|
`main` function.
|
||||||
|
|
||||||
The unit (`()`) type is there because nothing is really needed in terms of
|
The unit (`()`) type is there because nothing is really needed in terms of
|
||||||
positive results."""
|
positive results."""
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
// Solutions will be available before the stable release. Thank you for testing the beta version 🥰
|
// The exercise `intro1` only requires entering `n` in the terminal to go to the next exercise.
|
||||||
|
// It is just an introduction to how Rustlings works.
|
||||||
|
|
|
@ -1 +1,4 @@
|
||||||
// Solutions will be available before the stable release. Thank you for testing the beta version 🥰
|
fn main() {
|
||||||
|
// `println!` instead of `printline!`.
|
||||||
|
println!("Hello world!");
|
||||||
|
}
|
||||||
|
|
|
@ -1 +1,6 @@
|
||||||
// Solutions will be available before the stable release. Thank you for testing the beta version 🥰
|
fn main() {
|
||||||
|
// Declaring variables requires the `let` keyword.
|
||||||
|
let x = 5;
|
||||||
|
|
||||||
|
println!("x has the value {x}");
|
||||||
|
}
|
||||||
|
|
|
@ -1 +1,16 @@
|
||||||
// Solutions will be available before the stable release. Thank you for testing the beta version 🥰
|
fn main() {
|
||||||
|
// The easiest way to fix the compiler error is to initialize the
|
||||||
|
// variable `x`. By setting its value to an integer, Rust infers its type
|
||||||
|
// as `i32` which is the default type for integers.
|
||||||
|
let x = 42;
|
||||||
|
|
||||||
|
// But we can enforce a type different from the default `i32` by adding
|
||||||
|
// a type annotation:
|
||||||
|
// let x: u8 = 42;
|
||||||
|
|
||||||
|
if x == 10 {
|
||||||
|
println!("x is ten!");
|
||||||
|
} else {
|
||||||
|
println!("x is not ten!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1 +1,13 @@
|
||||||
// Solutions will be available before the stable release. Thank you for testing the beta version 🥰
|
fn main() {
|
||||||
|
// Reading uninitialized variables isn't allowed in Rust!
|
||||||
|
// Therefore, we need to assign a value first.
|
||||||
|
let x: i32 = 42;
|
||||||
|
|
||||||
|
println!("Number {x}");
|
||||||
|
|
||||||
|
// It possible to declare a variable and initialize it later.
|
||||||
|
// But it can't be used before initialization.
|
||||||
|
let y: i32;
|
||||||
|
y = 42;
|
||||||
|
println!("Number {y}");
|
||||||
|
}
|
||||||
|
|
|
@ -1 +1,9 @@
|
||||||
// Solutions will be available before the stable release. Thank you for testing the beta version 🥰
|
fn main() {
|
||||||
|
// In Rust, variables are immutable by default.
|
||||||
|
// Adding the `mut` keyword after `let` makes the declared variable mutable.
|
||||||
|
let mut x = 3;
|
||||||
|
println!("Number {x}");
|
||||||
|
|
||||||
|
x = 5; // Don't change this line
|
||||||
|
println!("Number {x}");
|
||||||
|
}
|
||||||
|
|
|
@ -1 +1,9 @@
|
||||||
// Solutions will be available before the stable release. Thank you for testing the beta version 🥰
|
fn main() {
|
||||||
|
let number = "T-H-R-E-E"; // Don't change this line
|
||||||
|
println!("Spell a number: {}", number);
|
||||||
|
|
||||||
|
// Using variable shadowing
|
||||||
|
// https://doc.rust-lang.org/book/ch03-01-variables-and-mutability.html#shadowing
|
||||||
|
let number = 3;
|
||||||
|
println!("Number plus two is: {}", number + 2);
|
||||||
|
}
|
||||||
|
|
|
@ -1 +1,6 @@
|
||||||
// Solutions will be available before the stable release. Thank you for testing the beta version 🥰
|
// The type of constants must always be annotated.
|
||||||
|
const NUMBER: u64 = 3;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
println!("Number: {NUMBER}");
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue