Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions dev/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,22 @@ bin = [
{ 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 = "strings1", path = "../exercises/10_strings/strings1.rs" },
{ name = "strings1_sol", path = "../solutions/10_strings/strings1.rs" },
{ name = "strings2", path = "../exercises/10_strings/strings2.rs" },
{ name = "strings2_sol", path = "../solutions/10_strings/strings2.rs" },
{ name = "strings3", path = "../exercises/10_strings/strings3.rs" },
{ name = "strings3_sol", path = "../solutions/10_strings/strings3.rs" },
{ name = "strings4", path = "../exercises/10_strings/strings4.rs" },
{ name = "strings4_sol", path = "../solutions/10_strings/strings4.rs" },
{ name = "modules1", path = "../exercises/09_modules/modules1.rs" },
{ name = "modules1_sol", path = "../solutions/09_modules/modules1.rs" },
{ name = "modules2", path = "../exercises/09_modules/modules2.rs" },
{ name = "modules2_sol", path = "../solutions/09_modules/modules2.rs" },
{ name = "modules3", path = "../exercises/09_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_sol", path = "../solutions/11_hashmaps/hashmaps1.rs" },
{ name = "hashmaps2", path = "../exercises/11_hashmaps/hashmaps2.rs" },
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions exercises/09_modules/fruit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub fn get_fav_fruit() {
println("Got your favourite fruit!")
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions exercises/09_modules/modules4.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// TODO: fix the compiler error for missing modules.

fn main() {
fruit::get_fav_fruit();
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
26 changes: 19 additions & 7 deletions rustlings-macros/info.toml
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ to get the variant's values."""

[[exercises]]
name = "strings1"
dir = "09_strings"
dir = "10_strings"
test = false
hint = """
The `current_favorite_color` function is currently returning a string slice
Expand All @@ -471,7 +471,7 @@ another way that uses the `From` trait."""

[[exercises]]
name = "strings2"
dir = "09_strings"
dir = "10_strings"
test = false
hint = """
Yes, it would be really easy to fix this by just changing the value bound to
Expand All @@ -486,7 +486,7 @@ https://doc.rust-lang.org/book/ch15-02-deref.html#implicit-deref-coercions-with-

[[exercises]]
name = "strings3"
dir = "09_strings"
dir = "10_strings"
hint = """
There are many useful standard library functions for strings. Let's try and use
some of them:
Expand All @@ -500,7 +500,7 @@ https://doc.rust-lang.org/std/string/struct.String.html#method.replace"""

[[exercises]]
name = "strings4"
dir = "09_strings"
dir = "10_strings"
test = false
hint = """
Replace `placeholder` with either `string` or `string_slice` in the `main`
Expand All @@ -516,15 +516,15 @@ because "blue" is `&str`, not `String`."""

[[exercises]]
name = "modules1"
dir = "10_modules"
dir = "09_modules"
test = false
hint = """
Everything is private in Rust by default. But there's a keyword we can use
to make something public!"""

[[exercises]]
name = "modules2"
dir = "10_modules"
dir = "09_modules"
test = false
hint = """
The `delicious_snacks` module is trying to present an external interface that
Expand All @@ -537,13 +537,25 @@ https://doc.rust-lang.org/book/ch07-04-bringing-paths-into-scope-with-the-use-ke

[[exercises]]
name = "modules3"
dir = "10_modules"
dir = "09_modules"
test = false
hint = """
`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
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

[[exercises]]
Expand Down
3 changes: 3 additions & 0 deletions solutions/09_modules/fruit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub fn get_fav_fruit() {
println("Got your favourite fruit!")
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions solutions/09_modules/modules4.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mod fruit;

fn main() {
fruit::get_fav_fruit();
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions src/cargo_toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ mod tests {
ExerciseInfo {
name: String::from("1"),
dir: None,
module_file: None,
test: true,
strict_clippy: true,
hint: String::new(),
Expand All @@ -116,6 +117,7 @@ mod tests {
ExerciseInfo {
name: String::from("2"),
dir: Some(String::from("d")),
module_file: None,
test: false,
strict_clippy: false,
hint: String::new(),
Expand Down
30 changes: 30 additions & 0 deletions src/info_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ pub struct ExerciseInfo {
pub name: String,
/// Exercise's directory name inside the `exercises/` directory.
pub dir: Option<String>,
/// Extra one Aditional Module file
#[serde(default)]
pub module_file: Option<String>,
/// Run `cargo test` on the exercise.
#[serde(default = "default_true")]
pub test: bool,
Expand Down Expand Up @@ -52,6 +55,33 @@ impl ExerciseInfo {

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 {
Expand Down
Loading