Merge 0219ef7cc99168e02c5fb142bcc1657dd8c354d1 into b5d440fdc3a1fadad6dc6196dad2acddabdc671f

This commit is contained in:
Eveeifyeve 2025-11-20 19:21:40 +07:00 committed by GitHub
commit 1b49ed86ca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
24 changed files with 83 additions and 21 deletions

View File

@ -72,20 +72,22 @@ bin = [
{ name = "enums2_sol", path = "../solutions/08_enums/enums2.rs" }, { name = "enums2_sol", path = "../solutions/08_enums/enums2.rs" },
{ name = "enums3", path = "../exercises/08_enums/enums3.rs" }, { name = "enums3", path = "../exercises/08_enums/enums3.rs" },
{ name = "enums3_sol", path = "../solutions/08_enums/enums3.rs" }, { name = "enums3_sol", path = "../solutions/08_enums/enums3.rs" },
{ name = "strings1", path = "../exercises/09_strings/strings1.rs" }, { name = "strings1", path = "../exercises/10_strings/strings1.rs" },
{ name = "strings1_sol", path = "../solutions/09_strings/strings1.rs" }, { name = "strings1_sol", path = "../solutions/10_strings/strings1.rs" },
{ name = "strings2", path = "../exercises/09_strings/strings2.rs" }, { name = "strings2", path = "../exercises/10_strings/strings2.rs" },
{ name = "strings2_sol", path = "../solutions/09_strings/strings2.rs" }, { name = "strings2_sol", path = "../solutions/10_strings/strings2.rs" },
{ name = "strings3", path = "../exercises/09_strings/strings3.rs" }, { name = "strings3", path = "../exercises/10_strings/strings3.rs" },
{ name = "strings3_sol", path = "../solutions/09_strings/strings3.rs" }, { name = "strings3_sol", path = "../solutions/10_strings/strings3.rs" },
{ name = "strings4", path = "../exercises/09_strings/strings4.rs" }, { name = "strings4", path = "../exercises/10_strings/strings4.rs" },
{ name = "strings4_sol", path = "../solutions/09_strings/strings4.rs" }, { name = "strings4_sol", path = "../solutions/10_strings/strings4.rs" },
{ name = "modules1", path = "../exercises/10_modules/modules1.rs" }, { name = "modules1", path = "../exercises/09_modules/modules1.rs" },
{ name = "modules1_sol", path = "../solutions/10_modules/modules1.rs" }, { name = "modules1_sol", path = "../solutions/09_modules/modules1.rs" },
{ name = "modules2", path = "../exercises/10_modules/modules2.rs" }, { name = "modules2", path = "../exercises/09_modules/modules2.rs" },
{ name = "modules2_sol", path = "../solutions/10_modules/modules2.rs" }, { name = "modules2_sol", path = "../solutions/09_modules/modules2.rs" },
{ name = "modules3", path = "../exercises/10_modules/modules3.rs" }, { name = "modules3", path = "../exercises/09_modules/modules3.rs" },
{ name = "modules3_sol", path = "../solutions/10_modules/modules3.rs" }, { name = "modules3_sol", path = "../solutions/09_modules/modules3.rs" },
{ name = "modules4", path = "../exercises/09_modules/modules4.rs" },
{ name = "modules4_sol", path = "../solutions/09_modules/modules4.rs" },
{ name = "hashmaps1", path = "../exercises/11_hashmaps/hashmaps1.rs" }, { name = "hashmaps1", path = "../exercises/11_hashmaps/hashmaps1.rs" },
{ name = "hashmaps1_sol", path = "../solutions/11_hashmaps/hashmaps1.rs" }, { name = "hashmaps1_sol", path = "../solutions/11_hashmaps/hashmaps1.rs" },
{ name = "hashmaps2", path = "../exercises/11_hashmaps/hashmaps2.rs" }, { name = "hashmaps2", path = "../exercises/11_hashmaps/hashmaps2.rs" },

View File

@ -0,0 +1,3 @@
pub fn get_fav_fruit() {
println("Got your favourite fruit!")
}

View File

@ -0,0 +1,5 @@
// TODO: fix the compiler error for missing modules.
fn main() {
fruit::get_fav_fruit();
}

View File

@ -457,7 +457,7 @@ to get the variant's values."""
[[exercises]] [[exercises]]
name = "strings1" name = "strings1"
dir = "09_strings" dir = "10_strings"
test = false test = false
hint = """ hint = """
The `current_favorite_color` function is currently returning a string slice The `current_favorite_color` function is currently returning a string slice
@ -471,7 +471,7 @@ another way that uses the `From` trait."""
[[exercises]] [[exercises]]
name = "strings2" name = "strings2"
dir = "09_strings" dir = "10_strings"
test = false test = false
hint = """ hint = """
Yes, it would be really easy to fix this by just changing the value bound to Yes, it would be really easy to fix this by just changing the value bound to
@ -486,7 +486,7 @@ https://doc.rust-lang.org/book/ch15-02-deref.html#implicit-deref-coercions-with-
[[exercises]] [[exercises]]
name = "strings3" name = "strings3"
dir = "09_strings" dir = "10_strings"
hint = """ hint = """
There are many useful standard library functions for strings. Let's try and use There are many useful standard library functions for strings. Let's try and use
some of them: some of them:
@ -500,7 +500,7 @@ https://doc.rust-lang.org/std/string/struct.String.html#method.replace"""
[[exercises]] [[exercises]]
name = "strings4" name = "strings4"
dir = "09_strings" dir = "10_strings"
test = false test = false
hint = """ hint = """
Replace `placeholder` with either `string` or `string_slice` in the `main` Replace `placeholder` with either `string` or `string_slice` in the `main`
@ -516,7 +516,7 @@ because "blue" is `&str`, not `String`."""
[[exercises]] [[exercises]]
name = "modules1" name = "modules1"
dir = "10_modules" dir = "09_modules"
test = false test = false
hint = """ hint = """
Everything is private in Rust by default. But there's a keyword we can use Everything is private in Rust by default. But there's a keyword we can use
@ -524,7 +524,7 @@ to make something public!"""
[[exercises]] [[exercises]]
name = "modules2" name = "modules2"
dir = "10_modules" dir = "09_modules"
test = false test = false
hint = """ hint = """
The `delicious_snacks` module is trying to present an external interface that The `delicious_snacks` module is trying to present an external interface that
@ -537,13 +537,25 @@ https://doc.rust-lang.org/book/ch07-04-bringing-paths-into-scope-with-the-use-ke
[[exercises]] [[exercises]]
name = "modules3" name = "modules3"
dir = "10_modules" dir = "09_modules"
test = false test = false
hint = """ hint = """
`UNIX_EPOCH` and `SystemTime` are declared in the `std::time` module. Add a `UNIX_EPOCH` and `SystemTime` are declared in the `std::time` module. Add a
`use` statement for these two to bring them into scope. You can use nested `use` statement for these two to bring them into scope. You can use nested
paths to bring these two in using only one line.""" paths to bring these two in using only one line."""
[[exercises]]
name = "modules4"
dir = "09_modules"
test = false
hint = """
The mod.rs is trying to use the modules from the file cake.rs and fruit directory.
Complete the `mod` statements to fit the use in `main`.
Learn more in The Book:
https://doc.rust-lang.org/book/ch07-05-separating-modules-into-different-files.html
"""
# HASHMAPS # HASHMAPS
[[exercises]] [[exercises]]

View File

@ -0,0 +1,3 @@
pub fn get_fav_fruit() {
println("Got your favourite fruit!")
}

View File

@ -0,0 +1,5 @@
mod fruit;
fn main() {
fruit::get_fav_fruit();
}

View File

@ -108,6 +108,7 @@ mod tests {
ExerciseInfo { ExerciseInfo {
name: String::from("1"), name: String::from("1"),
dir: None, dir: None,
module_file: None,
test: true, test: true,
strict_clippy: true, strict_clippy: true,
hint: String::new(), hint: String::new(),
@ -116,6 +117,7 @@ mod tests {
ExerciseInfo { ExerciseInfo {
name: String::from("2"), name: String::from("2"),
dir: Some(String::from("d")), dir: Some(String::from("d")),
module_file: None,
test: false, test: false,
strict_clippy: false, strict_clippy: false,
hint: String::new(), hint: String::new(),

View File

@ -11,6 +11,9 @@ pub struct ExerciseInfo {
pub name: String, pub name: String,
/// Exercise's directory name inside the `exercises/` directory. /// Exercise's directory name inside the `exercises/` directory.
pub dir: Option<String>, pub dir: Option<String>,
/// Extra one Aditional Module file
#[serde(default)]
pub module_file: Option<String>,
/// Run `cargo test` on the exercise. /// Run `cargo test` on the exercise.
#[serde(default = "default_true")] #[serde(default = "default_true")]
pub test: bool, pub test: bool,
@ -52,6 +55,33 @@ impl ExerciseInfo {
path path
} }
pub fn module_file_path(&self) -> Option<String> {
if let Some(module_path) = &self.module_file {
let mut path = if let Some(dir) = &self.dir {
// 14 = 10 + 1 + 3
// exercises/ + / + .rs
let mut path = String::with_capacity(14 + dir.len() + module_path.len());
path.push_str("exercises/");
path.push_str(dir);
path.push('/');
path
} else {
// 13 = 10 + 3
// exercises/ + .rs
let mut path = String::with_capacity(13 + module_path.len());
path.push_str("exercises/");
path
};
path.push_str(&module_path);
path.push_str(".rs");
Some(path)
} else {
None
}
}
} }
impl RunnableExercise for ExerciseInfo { impl RunnableExercise for ExerciseInfo {