mirror of
https://git.aramjonghu.dev/AramJonghu/rustlings.git
synced 2026-09-05 17:53:29 +02:00
progress(modules + hashmaps): finished modules and almost done hashmaps
This commit is contained in:
@@ -1,49 +0,0 @@
|
|||||||
#[derive(Debug)]
|
|
||||||
struct Order {
|
|
||||||
name: String,
|
|
||||||
year: u32,
|
|
||||||
made_by_phone: bool,
|
|
||||||
made_by_mobile: bool,
|
|
||||||
made_by_email: bool,
|
|
||||||
item_number: u32,
|
|
||||||
count: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn create_order_template() -> Order {
|
|
||||||
Order {
|
|
||||||
name: String::from("Bob"),
|
|
||||||
year: 2019,
|
|
||||||
made_by_phone: false,
|
|
||||||
made_by_mobile: false,
|
|
||||||
made_by_email: true,
|
|
||||||
item_number: 123,
|
|
||||||
count: 0,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
// You can optionally experiment here.
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn your_order() {
|
|
||||||
let order_template = create_order_template();
|
|
||||||
|
|
||||||
// TODO: Create your own order using the update syntax and template above!
|
|
||||||
// let your_order =
|
|
||||||
|
|
||||||
let your_order = ;
|
|
||||||
|
|
||||||
assert_eq!(your_order.name, "Hacker in Rust");
|
|
||||||
assert_eq!(your_order.year, order_template.year);
|
|
||||||
assert_eq!(your_order.made_by_phone, order_template.made_by_phone);
|
|
||||||
assert_eq!(your_order.made_by_mobile, order_template.made_by_mobile);
|
|
||||||
assert_eq!(your_order.made_by_email, order_template.made_by_email);
|
|
||||||
assert_eq!(your_order.item_number, order_template.item_number);
|
|
||||||
assert_eq!(your_order.count, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -5,7 +5,7 @@ mod sausage_factory {
|
|||||||
String::from("Ginger")
|
String::from("Ginger")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_sausage() {
|
pub fn make_sausage() {
|
||||||
get_secret_recipe();
|
get_secret_recipe();
|
||||||
println!("sausage!");
|
println!("sausage!");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,9 @@ mod delicious_snacks {
|
|||||||
// TODO: Add the following two `use` statements after fixing them.
|
// TODO: Add the following two `use` statements after fixing them.
|
||||||
// use self::fruits::PEAR as ???;
|
// use self::fruits::PEAR as ???;
|
||||||
// use self::veggies::CUCUMBER as ???;
|
// use self::veggies::CUCUMBER as ???;
|
||||||
|
|
||||||
|
pub use self::fruits::PEAR as fruit;
|
||||||
|
pub use self::veggies::CUCUMBER as veggie;
|
||||||
|
|
||||||
mod fruits {
|
mod fruits {
|
||||||
pub const PEAR: &str = "Pear";
|
pub const PEAR: &str = "Pear";
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
// TODO: Bring `SystemTime` and `UNIX_EPOCH` from the `std::time` module into
|
// TODO: Bring `SystemTime` and `UNIX_EPOCH` from the `std::time` module into
|
||||||
// your scope. Bonus style points if you can do it with one line!
|
// your scope. Bonus style points if you can do it with one line!
|
||||||
// use ???;
|
// use ???;
|
||||||
|
use std::time::SystemTime;
|
||||||
|
use std::time::UNIX_EPOCH;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
match SystemTime::now().duration_since(UNIX_EPOCH) {
|
match SystemTime::now().duration_since(UNIX_EPOCH) {
|
||||||
|
|||||||
@@ -9,10 +9,11 @@ use std::collections::HashMap;
|
|||||||
fn fruit_basket() -> HashMap<String, u32> {
|
fn fruit_basket() -> HashMap<String, u32> {
|
||||||
// TODO: Declare the hash map.
|
// TODO: Declare the hash map.
|
||||||
// let mut basket =
|
// let mut basket =
|
||||||
|
let mut basket = HashMap::new();
|
||||||
// Two bananas are already given for you :)
|
// Two bananas are already given for you :)
|
||||||
basket.insert(String::from("banana"), 2);
|
basket.insert(String::from("banana"), 2);
|
||||||
|
basket.insert(String::from("apple"), 2);
|
||||||
|
basket.insert(String::from("mango"), 1);
|
||||||
// TODO: Put more fruits in your basket.
|
// TODO: Put more fruits in your basket.
|
||||||
|
|
||||||
basket
|
basket
|
||||||
|
|||||||
@@ -28,10 +28,12 @@ fn fruit_basket(basket: &mut HashMap<Fruit, u32>) {
|
|||||||
Fruit::Pineapple,
|
Fruit::Pineapple,
|
||||||
];
|
];
|
||||||
|
|
||||||
for fruit in fruit_kinds {
|
for _fruit in fruit_kinds {
|
||||||
// TODO: Insert new fruits if they are not already present in the
|
// TODO: Insert new fruits if they are not already present in the
|
||||||
// basket. Note that you are not allowed to put any type of fruit that's
|
// basket. Note that you are not allowed to put any type of fruit that's
|
||||||
// already present!
|
// already present!
|
||||||
|
basket.insert(Fruit::Banana, 4);
|
||||||
|
basket.insert(Fruit::Pineapple, 3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user