mirror of
https://github.com/rust-lang/rustlings.git
synced 2025-12-28 06:49:19 +00:00
Merge 0219ef7cc99168e02c5fb142bcc1657dd8c354d1 into b5d440fdc3a1fadad6dc6196dad2acddabdc671f
This commit is contained in:
commit
1b49ed86ca
@ -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" },
|
||||
|
||||
3
exercises/09_modules/fruit.rs
Normal file
3
exercises/09_modules/fruit.rs
Normal file
@ -0,0 +1,3 @@
|
||||
pub fn get_fav_fruit() {
|
||||
println("Got your favourite fruit!")
|
||||
}
|
||||
5
exercises/09_modules/modules4.rs
Normal file
5
exercises/09_modules/modules4.rs
Normal file
@ -0,0 +1,5 @@
|
||||
// TODO: fix the compiler error for missing modules.
|
||||
|
||||
fn main() {
|
||||
fruit::get_fav_fruit();
|
||||
}
|
||||
@ -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
|
||||
@ -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
|
||||
@ -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:
|
||||
@ -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`
|
||||
@ -516,7 +516,7 @@ 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
|
||||
@ -524,7 +524,7 @@ 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
|
||||
@ -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]]
|
||||
|
||||
3
solutions/09_modules/fruit.rs
Normal file
3
solutions/09_modules/fruit.rs
Normal file
@ -0,0 +1,3 @@
|
||||
pub fn get_fav_fruit() {
|
||||
println("Got your favourite fruit!")
|
||||
}
|
||||
5
solutions/09_modules/modules4.rs
Normal file
5
solutions/09_modules/modules4.rs
Normal file
@ -0,0 +1,5 @@
|
||||
mod fruit;
|
||||
|
||||
fn main() {
|
||||
fruit::get_fav_fruit();
|
||||
}
|
||||
@ -108,6 +108,7 @@ mod tests {
|
||||
ExerciseInfo {
|
||||
name: String::from("1"),
|
||||
dir: None,
|
||||
module_file: None,
|
||||
test: true,
|
||||
strict_clippy: true,
|
||||
hint: String::new(),
|
||||
@ -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(),
|
||||
|
||||
@ -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,
|
||||
@ -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 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user