From 504738f2c9d379c44f61ddd2547795fbcd075d39 Mon Sep 17 00:00:00 2001 From: Hanai Date: Sat, 16 Jul 2022 21:30:40 +0800 Subject: [PATCH] exercises --- exercises/collections/vec1.rs | 4 +--- exercises/collections/vec2.rs | 5 +---- exercises/modules/modules1.rs | 4 +--- exercises/modules/modules2.rs | 7 ++----- exercises/modules/modules3.rs | 5 +---- 5 files changed, 6 insertions(+), 19 deletions(-) diff --git a/exercises/collections/vec1.rs b/exercises/collections/vec1.rs index b144fb94..6a7015a4 100644 --- a/exercises/collections/vec1.rs +++ b/exercises/collections/vec1.rs @@ -4,11 +4,9 @@ // Make me compile and pass the test! // Execute the command `rustlings hint vec1` if you need hints. -// I AM NOT DONE - fn array_and_vec() -> ([i32; 4], Vec) { let a = [10, 20, 30, 40]; // a plain array - let v = // TODO: declare your vector here with the macro for vectors + let v = Vec::from(a); (a, v) } diff --git a/exercises/collections/vec2.rs b/exercises/collections/vec2.rs index 6595e401..2b85627b 100644 --- a/exercises/collections/vec2.rs +++ b/exercises/collections/vec2.rs @@ -7,12 +7,9 @@ // Execute the command `rustlings hint vec2` if you need // hints. -// I AM NOT DONE - fn vec_loop(mut v: Vec) -> Vec { for i in v.iter_mut() { - // TODO: Fill this up so that each element in the Vec `v` is - // multiplied by 2. + *i *= 2; } // At this point, `v` should be equal to [4, 8, 12, 16, 20]. diff --git a/exercises/modules/modules1.rs b/exercises/modules/modules1.rs index 1a2bd0dd..3535a36a 100644 --- a/exercises/modules/modules1.rs +++ b/exercises/modules/modules1.rs @@ -1,15 +1,13 @@ // modules1.rs // Make me compile! Execute `rustlings hint modules1` for hints :) -// I AM NOT DONE - mod sausage_factory { // Don't let anybody outside of this module see this! fn get_secret_recipe() -> String { String::from("Ginger") } - fn make_sausage() { + pub fn make_sausage() { get_secret_recipe(); println!("sausage!"); } diff --git a/exercises/modules/modules2.rs b/exercises/modules/modules2.rs index 87f0c458..618c8fc5 100644 --- a/exercises/modules/modules2.rs +++ b/exercises/modules/modules2.rs @@ -3,13 +3,10 @@ // 'use' and 'as' keywords. Fix these 'use' statements to make the code compile. // Make me compile! Execute `rustlings hint modules2` for hints :) -// I AM NOT DONE - mod delicious_snacks { - // TODO: Fix these use statements - use self::fruits::PEAR as ??? - use self::veggies::CUCUMBER as ??? + pub use self::fruits::PEAR as fruit; + pub use self::veggies::CUCUMBER as veggie; mod fruits { pub const PEAR: &'static str = "Pear"; diff --git a/exercises/modules/modules3.rs b/exercises/modules/modules3.rs index 8eed77df..7881f4c5 100644 --- a/exercises/modules/modules3.rs +++ b/exercises/modules/modules3.rs @@ -5,10 +5,7 @@ // from the std::time module. Bonus style points if you can do it with one line! // Make me compile! Execute `rustlings hint modules3` for hints :) -// I AM NOT DONE - -// TODO: Complete this use statement -use ??? +use std::time::{SystemTime, UNIX_EPOCH}; fn main() { match SystemTime::now().duration_since(UNIX_EPOCH) {