Initial commit
This commit is contained in:
commit
7feaccd899
221 changed files with 8079 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
target/
|
||||||
98
.rustlings-state.txt
Normal file
98
.rustlings-state.txt
Normal file
|
|
@ -0,0 +1,98 @@
|
||||||
|
DON'T EDIT THIS FILE!
|
||||||
|
|
||||||
|
intro1
|
||||||
|
|
||||||
|
intro1
|
||||||
|
intro2
|
||||||
|
variables1
|
||||||
|
variables2
|
||||||
|
variables3
|
||||||
|
variables4
|
||||||
|
variables5
|
||||||
|
variables6
|
||||||
|
functions1
|
||||||
|
functions2
|
||||||
|
functions3
|
||||||
|
functions4
|
||||||
|
functions5
|
||||||
|
if1
|
||||||
|
if2
|
||||||
|
if3
|
||||||
|
quiz1
|
||||||
|
primitive_types1
|
||||||
|
primitive_types2
|
||||||
|
primitive_types3
|
||||||
|
primitive_types4
|
||||||
|
primitive_types5
|
||||||
|
primitive_types6
|
||||||
|
vecs1
|
||||||
|
vecs2
|
||||||
|
move_semantics1
|
||||||
|
move_semantics2
|
||||||
|
move_semantics3
|
||||||
|
move_semantics4
|
||||||
|
move_semantics5
|
||||||
|
structs1
|
||||||
|
structs2
|
||||||
|
structs3
|
||||||
|
enums1
|
||||||
|
enums2
|
||||||
|
enums3
|
||||||
|
strings1
|
||||||
|
strings2
|
||||||
|
strings3
|
||||||
|
strings4
|
||||||
|
modules1
|
||||||
|
modules2
|
||||||
|
modules3
|
||||||
|
hashmaps1
|
||||||
|
hashmaps2
|
||||||
|
hashmaps3
|
||||||
|
quiz2
|
||||||
|
options1
|
||||||
|
options2
|
||||||
|
options3
|
||||||
|
errors1
|
||||||
|
errors2
|
||||||
|
errors3
|
||||||
|
errors4
|
||||||
|
errors5
|
||||||
|
errors6
|
||||||
|
generics1
|
||||||
|
generics2
|
||||||
|
traits1
|
||||||
|
traits2
|
||||||
|
traits3
|
||||||
|
traits4
|
||||||
|
traits5
|
||||||
|
quiz3
|
||||||
|
lifetimes1
|
||||||
|
lifetimes2
|
||||||
|
lifetimes3
|
||||||
|
tests1
|
||||||
|
tests2
|
||||||
|
tests3
|
||||||
|
iterators1
|
||||||
|
iterators2
|
||||||
|
iterators3
|
||||||
|
iterators4
|
||||||
|
iterators5
|
||||||
|
box1
|
||||||
|
rc1
|
||||||
|
arc1
|
||||||
|
cow1
|
||||||
|
threads1
|
||||||
|
threads2
|
||||||
|
threads3
|
||||||
|
macros1
|
||||||
|
macros2
|
||||||
|
macros3
|
||||||
|
macros4
|
||||||
|
clippy1
|
||||||
|
clippy2
|
||||||
|
clippy3
|
||||||
|
using_as
|
||||||
|
from_into
|
||||||
|
from_str
|
||||||
|
try_from_into
|
||||||
|
as_ref_mut
|
||||||
7
Cargo.lock
generated
Normal file
7
Cargo.lock
generated
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "exercises"
|
||||||
|
version = "0.0.0"
|
||||||
222
Cargo.toml
Normal file
222
Cargo.toml
Normal file
|
|
@ -0,0 +1,222 @@
|
||||||
|
bin = [
|
||||||
|
{ name = "intro1", path = "exercises/00_intro/intro1.rs" },
|
||||||
|
{ name = "intro1_sol", path = "solutions/00_intro/intro1.rs" },
|
||||||
|
{ name = "intro2", path = "exercises/00_intro/intro2.rs" },
|
||||||
|
{ name = "intro2_sol", path = "solutions/00_intro/intro2.rs" },
|
||||||
|
{ name = "variables1", path = "exercises/01_variables/variables1.rs" },
|
||||||
|
{ name = "variables1_sol", path = "solutions/01_variables/variables1.rs" },
|
||||||
|
{ name = "variables2", path = "exercises/01_variables/variables2.rs" },
|
||||||
|
{ name = "variables2_sol", path = "solutions/01_variables/variables2.rs" },
|
||||||
|
{ name = "variables3", path = "exercises/01_variables/variables3.rs" },
|
||||||
|
{ name = "variables3_sol", path = "solutions/01_variables/variables3.rs" },
|
||||||
|
{ name = "variables4", path = "exercises/01_variables/variables4.rs" },
|
||||||
|
{ name = "variables4_sol", path = "solutions/01_variables/variables4.rs" },
|
||||||
|
{ name = "variables5", path = "exercises/01_variables/variables5.rs" },
|
||||||
|
{ name = "variables5_sol", path = "solutions/01_variables/variables5.rs" },
|
||||||
|
{ name = "variables6", path = "exercises/01_variables/variables6.rs" },
|
||||||
|
{ name = "variables6_sol", path = "solutions/01_variables/variables6.rs" },
|
||||||
|
{ name = "functions1", path = "exercises/02_functions/functions1.rs" },
|
||||||
|
{ name = "functions1_sol", path = "solutions/02_functions/functions1.rs" },
|
||||||
|
{ name = "functions2", path = "exercises/02_functions/functions2.rs" },
|
||||||
|
{ name = "functions2_sol", path = "solutions/02_functions/functions2.rs" },
|
||||||
|
{ name = "functions3", path = "exercises/02_functions/functions3.rs" },
|
||||||
|
{ name = "functions3_sol", path = "solutions/02_functions/functions3.rs" },
|
||||||
|
{ name = "functions4", path = "exercises/02_functions/functions4.rs" },
|
||||||
|
{ name = "functions4_sol", path = "solutions/02_functions/functions4.rs" },
|
||||||
|
{ name = "functions5", path = "exercises/02_functions/functions5.rs" },
|
||||||
|
{ name = "functions5_sol", path = "solutions/02_functions/functions5.rs" },
|
||||||
|
{ name = "if1", path = "exercises/03_if/if1.rs" },
|
||||||
|
{ name = "if1_sol", path = "solutions/03_if/if1.rs" },
|
||||||
|
{ name = "if2", path = "exercises/03_if/if2.rs" },
|
||||||
|
{ name = "if2_sol", path = "solutions/03_if/if2.rs" },
|
||||||
|
{ name = "if3", path = "exercises/03_if/if3.rs" },
|
||||||
|
{ name = "if3_sol", path = "solutions/03_if/if3.rs" },
|
||||||
|
{ name = "quiz1", path = "exercises/quizzes/quiz1.rs" },
|
||||||
|
{ name = "quiz1_sol", path = "solutions/quizzes/quiz1.rs" },
|
||||||
|
{ name = "primitive_types1", path = "exercises/04_primitive_types/primitive_types1.rs" },
|
||||||
|
{ name = "primitive_types1_sol", path = "solutions/04_primitive_types/primitive_types1.rs" },
|
||||||
|
{ name = "primitive_types2", path = "exercises/04_primitive_types/primitive_types2.rs" },
|
||||||
|
{ name = "primitive_types2_sol", path = "solutions/04_primitive_types/primitive_types2.rs" },
|
||||||
|
{ name = "primitive_types3", path = "exercises/04_primitive_types/primitive_types3.rs" },
|
||||||
|
{ name = "primitive_types3_sol", path = "solutions/04_primitive_types/primitive_types3.rs" },
|
||||||
|
{ name = "primitive_types4", path = "exercises/04_primitive_types/primitive_types4.rs" },
|
||||||
|
{ name = "primitive_types4_sol", path = "solutions/04_primitive_types/primitive_types4.rs" },
|
||||||
|
{ name = "primitive_types5", path = "exercises/04_primitive_types/primitive_types5.rs" },
|
||||||
|
{ name = "primitive_types5_sol", path = "solutions/04_primitive_types/primitive_types5.rs" },
|
||||||
|
{ name = "primitive_types6", path = "exercises/04_primitive_types/primitive_types6.rs" },
|
||||||
|
{ name = "primitive_types6_sol", path = "solutions/04_primitive_types/primitive_types6.rs" },
|
||||||
|
{ name = "vecs1", path = "exercises/05_vecs/vecs1.rs" },
|
||||||
|
{ name = "vecs1_sol", path = "solutions/05_vecs/vecs1.rs" },
|
||||||
|
{ name = "vecs2", path = "exercises/05_vecs/vecs2.rs" },
|
||||||
|
{ name = "vecs2_sol", path = "solutions/05_vecs/vecs2.rs" },
|
||||||
|
{ name = "move_semantics1", path = "exercises/06_move_semantics/move_semantics1.rs" },
|
||||||
|
{ name = "move_semantics1_sol", path = "solutions/06_move_semantics/move_semantics1.rs" },
|
||||||
|
{ name = "move_semantics2", path = "exercises/06_move_semantics/move_semantics2.rs" },
|
||||||
|
{ name = "move_semantics2_sol", path = "solutions/06_move_semantics/move_semantics2.rs" },
|
||||||
|
{ name = "move_semantics3", path = "exercises/06_move_semantics/move_semantics3.rs" },
|
||||||
|
{ name = "move_semantics3_sol", path = "solutions/06_move_semantics/move_semantics3.rs" },
|
||||||
|
{ name = "move_semantics4", path = "exercises/06_move_semantics/move_semantics4.rs" },
|
||||||
|
{ name = "move_semantics4_sol", path = "solutions/06_move_semantics/move_semantics4.rs" },
|
||||||
|
{ name = "move_semantics5", path = "exercises/06_move_semantics/move_semantics5.rs" },
|
||||||
|
{ name = "move_semantics5_sol", path = "solutions/06_move_semantics/move_semantics5.rs" },
|
||||||
|
{ name = "structs1", path = "exercises/07_structs/structs1.rs" },
|
||||||
|
{ name = "structs1_sol", path = "solutions/07_structs/structs1.rs" },
|
||||||
|
{ name = "structs2", path = "exercises/07_structs/structs2.rs" },
|
||||||
|
{ name = "structs2_sol", path = "solutions/07_structs/structs2.rs" },
|
||||||
|
{ name = "structs3", path = "exercises/07_structs/structs3.rs" },
|
||||||
|
{ name = "structs3_sol", path = "solutions/07_structs/structs3.rs" },
|
||||||
|
{ name = "enums1", path = "exercises/08_enums/enums1.rs" },
|
||||||
|
{ name = "enums1_sol", path = "solutions/08_enums/enums1.rs" },
|
||||||
|
{ name = "enums2", path = "exercises/08_enums/enums2.rs" },
|
||||||
|
{ name = "enums2_sol", path = "solutions/08_enums/enums2.rs" },
|
||||||
|
{ name = "enums3", path = "exercises/08_enums/enums3.rs" },
|
||||||
|
{ name = "enums3_sol", path = "solutions/08_enums/enums3.rs" },
|
||||||
|
{ name = "strings1", path = "exercises/09_strings/strings1.rs" },
|
||||||
|
{ name = "strings1_sol", path = "solutions/09_strings/strings1.rs" },
|
||||||
|
{ name = "strings2", path = "exercises/09_strings/strings2.rs" },
|
||||||
|
{ name = "strings2_sol", path = "solutions/09_strings/strings2.rs" },
|
||||||
|
{ name = "strings3", path = "exercises/09_strings/strings3.rs" },
|
||||||
|
{ name = "strings3_sol", path = "solutions/09_strings/strings3.rs" },
|
||||||
|
{ name = "strings4", path = "exercises/09_strings/strings4.rs" },
|
||||||
|
{ name = "strings4_sol", path = "solutions/09_strings/strings4.rs" },
|
||||||
|
{ name = "modules1", path = "exercises/10_modules/modules1.rs" },
|
||||||
|
{ name = "modules1_sol", path = "solutions/10_modules/modules1.rs" },
|
||||||
|
{ name = "modules2", path = "exercises/10_modules/modules2.rs" },
|
||||||
|
{ name = "modules2_sol", path = "solutions/10_modules/modules2.rs" },
|
||||||
|
{ name = "modules3", path = "exercises/10_modules/modules3.rs" },
|
||||||
|
{ name = "modules3_sol", path = "solutions/10_modules/modules3.rs" },
|
||||||
|
{ name = "hashmaps1", path = "exercises/11_hashmaps/hashmaps1.rs" },
|
||||||
|
{ name = "hashmaps1_sol", path = "solutions/11_hashmaps/hashmaps1.rs" },
|
||||||
|
{ name = "hashmaps2", path = "exercises/11_hashmaps/hashmaps2.rs" },
|
||||||
|
{ name = "hashmaps2_sol", path = "solutions/11_hashmaps/hashmaps2.rs" },
|
||||||
|
{ name = "hashmaps3", path = "exercises/11_hashmaps/hashmaps3.rs" },
|
||||||
|
{ name = "hashmaps3_sol", path = "solutions/11_hashmaps/hashmaps3.rs" },
|
||||||
|
{ name = "quiz2", path = "exercises/quizzes/quiz2.rs" },
|
||||||
|
{ name = "quiz2_sol", path = "solutions/quizzes/quiz2.rs" },
|
||||||
|
{ name = "options1", path = "exercises/12_options/options1.rs" },
|
||||||
|
{ name = "options1_sol", path = "solutions/12_options/options1.rs" },
|
||||||
|
{ name = "options2", path = "exercises/12_options/options2.rs" },
|
||||||
|
{ name = "options2_sol", path = "solutions/12_options/options2.rs" },
|
||||||
|
{ name = "options3", path = "exercises/12_options/options3.rs" },
|
||||||
|
{ name = "options3_sol", path = "solutions/12_options/options3.rs" },
|
||||||
|
{ name = "errors1", path = "exercises/13_error_handling/errors1.rs" },
|
||||||
|
{ name = "errors1_sol", path = "solutions/13_error_handling/errors1.rs" },
|
||||||
|
{ name = "errors2", path = "exercises/13_error_handling/errors2.rs" },
|
||||||
|
{ name = "errors2_sol", path = "solutions/13_error_handling/errors2.rs" },
|
||||||
|
{ name = "errors3", path = "exercises/13_error_handling/errors3.rs" },
|
||||||
|
{ name = "errors3_sol", path = "solutions/13_error_handling/errors3.rs" },
|
||||||
|
{ name = "errors4", path = "exercises/13_error_handling/errors4.rs" },
|
||||||
|
{ name = "errors4_sol", path = "solutions/13_error_handling/errors4.rs" },
|
||||||
|
{ name = "errors5", path = "exercises/13_error_handling/errors5.rs" },
|
||||||
|
{ name = "errors5_sol", path = "solutions/13_error_handling/errors5.rs" },
|
||||||
|
{ name = "errors6", path = "exercises/13_error_handling/errors6.rs" },
|
||||||
|
{ name = "errors6_sol", path = "solutions/13_error_handling/errors6.rs" },
|
||||||
|
{ name = "generics1", path = "exercises/14_generics/generics1.rs" },
|
||||||
|
{ name = "generics1_sol", path = "solutions/14_generics/generics1.rs" },
|
||||||
|
{ name = "generics2", path = "exercises/14_generics/generics2.rs" },
|
||||||
|
{ name = "generics2_sol", path = "solutions/14_generics/generics2.rs" },
|
||||||
|
{ name = "traits1", path = "exercises/15_traits/traits1.rs" },
|
||||||
|
{ name = "traits1_sol", path = "solutions/15_traits/traits1.rs" },
|
||||||
|
{ name = "traits2", path = "exercises/15_traits/traits2.rs" },
|
||||||
|
{ name = "traits2_sol", path = "solutions/15_traits/traits2.rs" },
|
||||||
|
{ name = "traits3", path = "exercises/15_traits/traits3.rs" },
|
||||||
|
{ name = "traits3_sol", path = "solutions/15_traits/traits3.rs" },
|
||||||
|
{ name = "traits4", path = "exercises/15_traits/traits4.rs" },
|
||||||
|
{ name = "traits4_sol", path = "solutions/15_traits/traits4.rs" },
|
||||||
|
{ name = "traits5", path = "exercises/15_traits/traits5.rs" },
|
||||||
|
{ name = "traits5_sol", path = "solutions/15_traits/traits5.rs" },
|
||||||
|
{ name = "quiz3", path = "exercises/quizzes/quiz3.rs" },
|
||||||
|
{ name = "quiz3_sol", path = "solutions/quizzes/quiz3.rs" },
|
||||||
|
{ name = "lifetimes1", path = "exercises/16_lifetimes/lifetimes1.rs" },
|
||||||
|
{ name = "lifetimes1_sol", path = "solutions/16_lifetimes/lifetimes1.rs" },
|
||||||
|
{ name = "lifetimes2", path = "exercises/16_lifetimes/lifetimes2.rs" },
|
||||||
|
{ name = "lifetimes2_sol", path = "solutions/16_lifetimes/lifetimes2.rs" },
|
||||||
|
{ name = "lifetimes3", path = "exercises/16_lifetimes/lifetimes3.rs" },
|
||||||
|
{ name = "lifetimes3_sol", path = "solutions/16_lifetimes/lifetimes3.rs" },
|
||||||
|
{ name = "tests1", path = "exercises/17_tests/tests1.rs" },
|
||||||
|
{ name = "tests1_sol", path = "solutions/17_tests/tests1.rs" },
|
||||||
|
{ name = "tests2", path = "exercises/17_tests/tests2.rs" },
|
||||||
|
{ name = "tests2_sol", path = "solutions/17_tests/tests2.rs" },
|
||||||
|
{ name = "tests3", path = "exercises/17_tests/tests3.rs" },
|
||||||
|
{ name = "tests3_sol", path = "solutions/17_tests/tests3.rs" },
|
||||||
|
{ name = "iterators1", path = "exercises/18_iterators/iterators1.rs" },
|
||||||
|
{ name = "iterators1_sol", path = "solutions/18_iterators/iterators1.rs" },
|
||||||
|
{ name = "iterators2", path = "exercises/18_iterators/iterators2.rs" },
|
||||||
|
{ name = "iterators2_sol", path = "solutions/18_iterators/iterators2.rs" },
|
||||||
|
{ name = "iterators3", path = "exercises/18_iterators/iterators3.rs" },
|
||||||
|
{ name = "iterators3_sol", path = "solutions/18_iterators/iterators3.rs" },
|
||||||
|
{ name = "iterators4", path = "exercises/18_iterators/iterators4.rs" },
|
||||||
|
{ name = "iterators4_sol", path = "solutions/18_iterators/iterators4.rs" },
|
||||||
|
{ name = "iterators5", path = "exercises/18_iterators/iterators5.rs" },
|
||||||
|
{ name = "iterators5_sol", path = "solutions/18_iterators/iterators5.rs" },
|
||||||
|
{ name = "box1", path = "exercises/19_smart_pointers/box1.rs" },
|
||||||
|
{ name = "box1_sol", path = "solutions/19_smart_pointers/box1.rs" },
|
||||||
|
{ name = "rc1", path = "exercises/19_smart_pointers/rc1.rs" },
|
||||||
|
{ name = "rc1_sol", path = "solutions/19_smart_pointers/rc1.rs" },
|
||||||
|
{ name = "arc1", path = "exercises/19_smart_pointers/arc1.rs" },
|
||||||
|
{ name = "arc1_sol", path = "solutions/19_smart_pointers/arc1.rs" },
|
||||||
|
{ name = "cow1", path = "exercises/19_smart_pointers/cow1.rs" },
|
||||||
|
{ name = "cow1_sol", path = "solutions/19_smart_pointers/cow1.rs" },
|
||||||
|
{ name = "threads1", path = "exercises/20_threads/threads1.rs" },
|
||||||
|
{ name = "threads1_sol", path = "solutions/20_threads/threads1.rs" },
|
||||||
|
{ name = "threads2", path = "exercises/20_threads/threads2.rs" },
|
||||||
|
{ name = "threads2_sol", path = "solutions/20_threads/threads2.rs" },
|
||||||
|
{ name = "threads3", path = "exercises/20_threads/threads3.rs" },
|
||||||
|
{ name = "threads3_sol", path = "solutions/20_threads/threads3.rs" },
|
||||||
|
{ name = "macros1", path = "exercises/21_macros/macros1.rs" },
|
||||||
|
{ name = "macros1_sol", path = "solutions/21_macros/macros1.rs" },
|
||||||
|
{ name = "macros2", path = "exercises/21_macros/macros2.rs" },
|
||||||
|
{ name = "macros2_sol", path = "solutions/21_macros/macros2.rs" },
|
||||||
|
{ name = "macros3", path = "exercises/21_macros/macros3.rs" },
|
||||||
|
{ name = "macros3_sol", path = "solutions/21_macros/macros3.rs" },
|
||||||
|
{ name = "macros4", path = "exercises/21_macros/macros4.rs" },
|
||||||
|
{ name = "macros4_sol", path = "solutions/21_macros/macros4.rs" },
|
||||||
|
{ name = "clippy1", path = "exercises/22_clippy/clippy1.rs" },
|
||||||
|
{ name = "clippy1_sol", path = "solutions/22_clippy/clippy1.rs" },
|
||||||
|
{ name = "clippy2", path = "exercises/22_clippy/clippy2.rs" },
|
||||||
|
{ name = "clippy2_sol", path = "solutions/22_clippy/clippy2.rs" },
|
||||||
|
{ name = "clippy3", path = "exercises/22_clippy/clippy3.rs" },
|
||||||
|
{ name = "clippy3_sol", path = "solutions/22_clippy/clippy3.rs" },
|
||||||
|
{ name = "using_as", path = "exercises/23_conversions/using_as.rs" },
|
||||||
|
{ name = "using_as_sol", path = "solutions/23_conversions/using_as.rs" },
|
||||||
|
{ name = "from_into", path = "exercises/23_conversions/from_into.rs" },
|
||||||
|
{ name = "from_into_sol", path = "solutions/23_conversions/from_into.rs" },
|
||||||
|
{ name = "from_str", path = "exercises/23_conversions/from_str.rs" },
|
||||||
|
{ name = "from_str_sol", path = "solutions/23_conversions/from_str.rs" },
|
||||||
|
{ name = "try_from_into", path = "exercises/23_conversions/try_from_into.rs" },
|
||||||
|
{ name = "try_from_into_sol", path = "solutions/23_conversions/try_from_into.rs" },
|
||||||
|
{ name = "as_ref_mut", path = "exercises/23_conversions/as_ref_mut.rs" },
|
||||||
|
{ name = "as_ref_mut_sol", path = "solutions/23_conversions/as_ref_mut.rs" },
|
||||||
|
]
|
||||||
|
|
||||||
|
[package]
|
||||||
|
name = "exercises"
|
||||||
|
edition = "2021"
|
||||||
|
# Don't publish the exercises on crates.io!
|
||||||
|
publish = false
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
panic = "abort"
|
||||||
|
|
||||||
|
[profile.dev]
|
||||||
|
panic = "abort"
|
||||||
|
|
||||||
|
[lints.rust]
|
||||||
|
# You shouldn't write unsafe code in Rustlings!
|
||||||
|
unsafe_code = "forbid"
|
||||||
|
# You don't need unstable features in Rustlings and shouldn't rely on them while learning Rust.
|
||||||
|
unstable_features = "forbid"
|
||||||
|
# Dead code warnings can't be avoided in some exercises and might distract while learning.
|
||||||
|
dead_code = "allow"
|
||||||
|
|
||||||
|
[lints.clippy]
|
||||||
|
# You forgot a `todo!()`!
|
||||||
|
todo = "forbid"
|
||||||
|
# This can only happen by mistake in Rustlings.
|
||||||
|
empty_loop = "forbid"
|
||||||
|
# No infinite loops are needed in Rustlings.
|
||||||
|
infinite_loop = "deny"
|
||||||
|
# You shouldn't leak memory while still learning Rust!
|
||||||
|
mem_forget = "deny"
|
||||||
|
# Currently, there are no disallowed methods. This line avoids problems when developing Rustlings.
|
||||||
|
disallowed_methods = "allow"
|
||||||
5
README.md
Normal file
5
README.md
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
# rustlings
|
||||||
|
|
||||||
|
Rustlings practice.
|
||||||
|
|
||||||
|
https://github.com/rust-lang/rustlings
|
||||||
8
exercises/00_intro/README.md
Normal file
8
exercises/00_intro/README.md
Normal 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)
|
||||||
24
exercises/00_intro/intro1.rs
Normal file
24
exercises/00_intro/intro1.rs
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
// TODO: 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, enter `n` in the terminal.
|
||||||
|
//
|
||||||
|
// The exercise file will be reloaded when you change one of the lines below!
|
||||||
|
// Try adding a new `println!` and check the updated output in the terminal.
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
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!");
|
||||||
|
println!();
|
||||||
|
println!("The file of this exercise is `exercises/00_intro/intro1.rs`. Have a look!");
|
||||||
|
println!("The current exercise path will be always shown under the progress bar.");
|
||||||
|
println!("You can click on the path to open the exercise file in your editor.");
|
||||||
|
}
|
||||||
4
exercises/00_intro/intro2.rs
Normal file
4
exercises/00_intro/intro2.rs
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
fn main() {
|
||||||
|
// TODO: Fix the code to print "Hello world!".
|
||||||
|
println!("Hello world!");
|
||||||
|
}
|
||||||
9
exercises/01_variables/README.md
Normal file
9
exercises/01_variables/README.md
Normal 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 can’t 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)
|
||||||
6
exercises/01_variables/variables1.rs
Normal file
6
exercises/01_variables/variables1.rs
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
fn main() {
|
||||||
|
// TODO: Add the missing keyword.
|
||||||
|
let x = 5;
|
||||||
|
|
||||||
|
println!("x has the value {x}");
|
||||||
|
}
|
||||||
10
exercises/01_variables/variables2.rs
Normal file
10
exercises/01_variables/variables2.rs
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
fn main() {
|
||||||
|
// TODO: Change the line below to fix the compiler error.
|
||||||
|
let x = 0;
|
||||||
|
|
||||||
|
if x == 10 {
|
||||||
|
println!("x is ten!");
|
||||||
|
} else {
|
||||||
|
println!("x is not ten!");
|
||||||
|
}
|
||||||
|
}
|
||||||
6
exercises/01_variables/variables3.rs
Normal file
6
exercises/01_variables/variables3.rs
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
fn main() {
|
||||||
|
// TODO: Change the line below to fix the compiler error.
|
||||||
|
let x: i32 = 0;
|
||||||
|
|
||||||
|
println!("Number {x}");
|
||||||
|
}
|
||||||
8
exercises/01_variables/variables4.rs
Normal file
8
exercises/01_variables/variables4.rs
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
// TODO: Fix the compiler error.
|
||||||
|
fn main() {
|
||||||
|
let mut x = 3;
|
||||||
|
println!("Number {x}");
|
||||||
|
|
||||||
|
x = 5; // Don't change this line
|
||||||
|
println!("Number {x}");
|
||||||
|
}
|
||||||
8
exercises/01_variables/variables5.rs
Normal file
8
exercises/01_variables/variables5.rs
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
fn main() {
|
||||||
|
let number = "T-H-R-E-E"; // Don't change this line
|
||||||
|
println!("Spell a number: {}", number);
|
||||||
|
|
||||||
|
// TODO: Fix the compiler error by changing the line below without renaming the variable.
|
||||||
|
let number = 3;
|
||||||
|
println!("Number plus two is: {}", number + 2);
|
||||||
|
}
|
||||||
6
exercises/01_variables/variables6.rs
Normal file
6
exercises/01_variables/variables6.rs
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
// TODO: Change the line below to fix the compiler error.
|
||||||
|
const NUMBER: i32 = 3;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
println!("Number: {NUMBER}");
|
||||||
|
}
|
||||||
8
exercises/02_functions/README.md
Normal file
8
exercises/02_functions/README.md
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
# Functions
|
||||||
|
|
||||||
|
Here, you'll learn how to write functions and how the Rust compiler can help you debug errors even
|
||||||
|
in more complex code.
|
||||||
|
|
||||||
|
## Further information
|
||||||
|
|
||||||
|
- [How Functions Work](https://doc.rust-lang.org/book/ch03-03-how-functions-work.html)
|
||||||
7
exercises/02_functions/functions1.rs
Normal file
7
exercises/02_functions/functions1.rs
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
// TODO: Add some function with the name `call_me` without arguments or a return value.
|
||||||
|
|
||||||
|
fn call_me() {}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
call_me(); // Don't change this line
|
||||||
|
}
|
||||||
10
exercises/02_functions/functions2.rs
Normal file
10
exercises/02_functions/functions2.rs
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
// TODO: Add the missing type of the argument `num` after the colon `:`.
|
||||||
|
fn call_me(num: i32) {
|
||||||
|
for i in 0..num {
|
||||||
|
println!("Ring! Call number {}", i + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
call_me(3);
|
||||||
|
}
|
||||||
10
exercises/02_functions/functions3.rs
Normal file
10
exercises/02_functions/functions3.rs
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
fn call_me(num: u8) {
|
||||||
|
for i in 0..num {
|
||||||
|
println!("Ring! Call number {}", i + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
// TODO: Fix the function call.
|
||||||
|
call_me(3);
|
||||||
|
}
|
||||||
22
exercises/02_functions/functions4.rs
Normal file
22
exercises/02_functions/functions4.rs
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
// This store is having a sale where if the price is an even number, you get 10
|
||||||
|
// Rustbucks off, but if it's an odd number, it's 3 Rustbucks off.
|
||||||
|
// Don't worry about the function bodies themselves, we are only interested in
|
||||||
|
// the signatures for now.
|
||||||
|
|
||||||
|
fn is_even(num: i64) -> bool {
|
||||||
|
num % 2 == 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Fix the function signature.
|
||||||
|
fn sale_price(price: i64) -> i64 {
|
||||||
|
if is_even(price) {
|
||||||
|
price - 10
|
||||||
|
} else {
|
||||||
|
price - 3
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let original_price = 51;
|
||||||
|
println!("Your sale price is {}", sale_price(original_price));
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue