Skip to content

Commit

Permalink
do everything up to and inc strings
Browse files Browse the repository at this point in the history
stopped before error handling
  • Loading branch information
maradude committed Mar 25, 2022
1 parent 18672fa commit d3472bf
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 28 deletions.
5 changes: 3 additions & 2 deletions exercises/collections/hashmap1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,18 @@
// Execute the command `rustlings hint hashmap1` if you need
// hints.

// I AM NOT DONE

use std::collections::HashMap;

fn fruit_basket() -> HashMap<String, u32> {
let mut basket = // TODO: declare your hash map here.
let mut basket = HashMap::new();// TODO: declare your hash map here.

// Two bananas are already given for you :)
basket.insert(String::from("banana"), 2);

// TODO: Put more fruits in your basket here.
let fruits = [("tomato".to_string(), 3), ("apple".to_string(), 4), ("orange".to_string(), 5)];
basket.extend(fruits);

basket
}
Expand Down
2 changes: 1 addition & 1 deletion exercises/collections/hashmap2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// Execute the command `rustlings hint hashmap2` if you need
// hints.

// I AM NOT DONE

use std::collections::HashMap;

Expand All @@ -38,6 +37,7 @@ fn fruit_basket(basket: &mut HashMap<Fruit, u32>) {
// TODO: Put new fruits if not already present. Note that you
// are not allowed to put any type of fruit that's already
// present!
let ent = basket.entry(fruit).or_insert(1);
}
}

Expand Down
3 changes: 1 addition & 2 deletions exercises/collections/vec1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
// 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<i32>) {
let a = [10, 20, 30, 40]; // a plain array
let v = // TODO: declare your vector here with the macro for vectors
let v = vec![10, 20, 30, 40]; // TODO: declare your vector here with the macro for vectors

(a, v)
}
Expand Down
2 changes: 1 addition & 1 deletion exercises/collections/vec2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
// Execute the command `rustlings hint vec2` if you need
// hints.

// I AM NOT DONE

fn vec_loop(mut v: Vec<i32>) -> Vec<i32> {
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].
Expand Down
3 changes: 1 addition & 2 deletions exercises/modules/modules1.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
// 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!");
}
Expand Down
5 changes: 2 additions & 3 deletions exercises/modules/modules2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
// '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";
Expand Down
3 changes: 1 addition & 2 deletions exercises/modules/modules3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
// 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) {
Expand Down
21 changes: 10 additions & 11 deletions exercises/quiz2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
// you think each value is. That is, add either `string_slice` or `string`
// before the parentheses on each line. If you're right, it will compile!

// I AM NOT DONE

fn string_slice(arg: &str) {
println!("{}", arg);
Expand All @@ -17,14 +16,14 @@ fn string(arg: String) {
}

fn main() {
???("blue");
???("red".to_string());
???(String::from("hi"));
???("rust is fun!".to_owned());
???("nice weather".into());
???(format!("Interpolation {}", "Station"));
???(&String::from("abc")[0..1]);
???(" hello there ".trim());
???("Happy Monday!".to_string().replace("Mon", "Tues"));
???("mY sHiFt KeY iS sTiCkY".to_lowercase());
string_slice("blue");
string("red".to_string());
string(String::from("hi"));
string("rust is fun!".to_owned());
string("nice weather".into());
string(format!("Interpolation {}", "Station"));
string_slice(&String::from("abc")[0..1]);
string_slice(" hello there ".trim());
string("Happy Monday!".to_string().replace("Mon", "Tues"));
string("mY sHiFt KeY iS sTiCkY".to_lowercase());
}
3 changes: 1 addition & 2 deletions exercises/strings/strings1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
// Make me compile without changing the function signature!
// Execute `rustlings hint strings1` for hints ;)

// I AM NOT DONE

fn main() {
let answer = current_favorite_color();
println!("My current favorite color is {}", answer);
}

fn current_favorite_color() -> String {
"blue"
"blue".to_string()
}
3 changes: 1 addition & 2 deletions exercises/strings/strings2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
// Make me compile without changing the function signature!
// Execute `rustlings hint strings2` for hints :)

// I AM NOT DONE

fn main() {
let word = String::from("green"); // Try not changing this line :)
if is_a_color_word(word) {
if is_a_color_word(&word) {
println!("That is a color word I know!");
} else {
println!("That is not a color word I know.");
Expand Down

0 comments on commit d3472bf

Please sign in to comment.