diff --git a/exercises/advanced_errors/advanced_errs1.rs b/exercises/advanced_errors/advanced_errs1.rs index f83ce333..4bc7b635 100644 --- a/exercises/advanced_errors/advanced_errs1.rs +++ b/exercises/advanced_errors/advanced_errs1.rs @@ -7,6 +7,8 @@ // Make this code compile! Execute `rustlings hint advanced_errs1` for // hints :) +// I AM NOT DONE + use std::num::ParseIntError; use std::str::FromStr; @@ -22,7 +24,6 @@ impl From for ParsePosNonzeroError { fn from(e: CreationError) -> Self { // TODO: complete this implementation so that the `?` operator will // work for `CreationError` - ParsePosNonzeroError::Creation(e) } } @@ -30,14 +31,6 @@ impl From for ParsePosNonzeroError { // `?` operator will work in the other place in the `FromStr` // implementation below. -impl From for ParsePosNonzeroError { - fn from(e: ParseIntError) -> Self { - // TODO: complete this implementation so that the `?` operator will - // work for `CreationError` - ParsePosNonzeroError::ParseInt(e) - } -} - // Don't change anything below this line. impl FromStr for PositiveNonzeroInteger { diff --git a/exercises/clippy/clippy1.rs b/exercises/clippy/clippy1.rs index 142e4887..c5f84a9c 100644 --- a/exercises/clippy/clippy1.rs +++ b/exercises/clippy/clippy1.rs @@ -6,10 +6,12 @@ // check clippy's suggestions from the output to solve the exercise. // Execute `rustlings hint clippy1` for hints :) -use std::f32::{self, consts::PI}; +// I AM NOT DONE + +use std::f32; fn main() { - let pi = PI; + let pi = 3.14f32; let radius = 5.00f32; let area = pi * f32::powi(radius, 2); diff --git a/exercises/clippy/clippy2.rs b/exercises/clippy/clippy2.rs index 4cdfbe75..37af9ed0 100644 --- a/exercises/clippy/clippy2.rs +++ b/exercises/clippy/clippy2.rs @@ -1,10 +1,12 @@ // clippy2.rs // Make me compile! Execute `rustlings hint clippy2` for hints :) +// I AM NOT DONE + fn main() { let mut res = 42; let option = Some(12); - if let Some(x) = option { + for x in option { res += x; } println!("{}", res); diff --git a/exercises/conversions/as_ref_mut.rs b/exercises/conversions/as_ref_mut.rs index f1e5072e..84f4a60c 100644 --- a/exercises/conversions/as_ref_mut.rs +++ b/exercises/conversions/as_ref_mut.rs @@ -2,15 +2,17 @@ // Read more about them at https://doc.rust-lang.org/std/convert/trait.AsRef.html // and https://doc.rust-lang.org/std/convert/trait.AsMut.html, respectively. +// I AM NOT DONE + // Obtain the number of bytes (not characters) in the given argument // Add the AsRef trait appropriately as a trait bound -fn byte_counter>(arg: T) -> usize { +fn byte_counter(arg: T) -> usize { arg.as_ref().as_bytes().len() } // Obtain the number of characters (not bytes) in the given argument // Add the AsRef trait appropriately as a trait bound -fn char_counter>(arg: T) -> usize { +fn char_counter(arg: T) -> usize { arg.as_ref().chars().count() } diff --git a/exercises/conversions/from_into.rs b/exercises/conversions/from_into.rs index ada1423f..9d84174d 100644 --- a/exercises/conversions/from_into.rs +++ b/exercises/conversions/from_into.rs @@ -33,30 +33,10 @@ impl Default for Person { // If while parsing the age, something goes wrong, then return the default of Person // Otherwise, then return an instantiated Person object with the results +// I AM NOT DONE + impl From<&str> for Person { fn from(s: &str) -> Person { - if s.len() == 0 { - return Person::default() - } - - let split: Vec<&str> = s.split(",").collect(); - - if split.len() != 2 { - return Person::default() - } - - if split[0].len() == 0 { - return Person::default() - } - - let age = split[1].parse::(); - - let mut age = match age { - Ok(age) => age, - Err(_) => return Person::default(), - }; - - Person { name: String::from(split[0]), age } } } diff --git a/exercises/conversions/from_str.rs b/exercises/conversions/from_str.rs index 381f9560..ece0b3cf 100644 --- a/exercises/conversions/from_str.rs +++ b/exercises/conversions/from_str.rs @@ -26,6 +26,8 @@ enum ParsePersonError { ParseInt(ParseIntError), } +// I AM NOT DONE + // Steps: // 1. If the length of the provided string is 0, an error should be returned // 2. Split the given string on the commas present in it @@ -39,28 +41,6 @@ enum ParsePersonError { impl FromStr for Person { type Err = ParsePersonError; fn from_str(s: &str) -> Result { - if s.len() == 0 { - return Err(ParsePersonError::Empty); - } - - let split: Vec<&str> = s.split(",").collect(); - - if split.len() != 2 { - return Err(ParsePersonError::BadLen); - } - - let name = match split[0].len() { - 0 => return Err(ParsePersonError::NoName), - _ => split[0] - }; - - let age = split[1].parse::(); - let mut age = match age { - Ok(age) => age, - Err(err) => return Err(ParsePersonError::ParseInt(err)) - }; - - Ok(Person { name: String::from(name), age }) } } diff --git a/exercises/conversions/try_from_into.rs b/exercises/conversions/try_from_into.rs index 9bc3ded2..b8ec4455 100644 --- a/exercises/conversions/try_from_into.rs +++ b/exercises/conversions/try_from_into.rs @@ -21,6 +21,8 @@ enum IntoColorError { IntConversion, } +// I AM NOT DONE + // Your task is to complete this implementation // and return an Ok result of inner type Color. // You need to create an implementation for a tuple of three integers, @@ -34,12 +36,6 @@ enum IntoColorError { impl TryFrom<(i16, i16, i16)> for Color { type Error = IntoColorError; fn try_from(tuple: (i16, i16, i16)) -> Result { - match tuple { - x if x.0 < 0 || x.0 > 255 => return Err(IntoColorError::IntConversion), - x if x.1 < 0 || x.1 > 255 => return Err(IntoColorError::IntConversion), - x if x.2 < 0 || x.2 > 255 => return Err(IntoColorError::IntConversion), - x => Ok(Color {red: x.0 as u8, green: x.1 as u8, blue: x.2 as u8}) - } } } @@ -47,12 +43,6 @@ impl TryFrom<(i16, i16, i16)> for Color { impl TryFrom<[i16; 3]> for Color { type Error = IntoColorError; fn try_from(arr: [i16; 3]) -> Result { - match arr { - x if x[0] < 0 || x[0] > 255 => return Err(IntoColorError::IntConversion), - x if x[1] < 0 || x[1] > 255 => return Err(IntoColorError::IntConversion), - x if x[2] < 0 || x[2] > 255 => return Err(IntoColorError::IntConversion), - x => Ok(Color {red: x[0] as u8, green: x[1] as u8, blue: x[2] as u8}) - } } } @@ -60,13 +50,6 @@ impl TryFrom<[i16; 3]> for Color { impl TryFrom<&[i16]> for Color { type Error = IntoColorError; fn try_from(slice: &[i16]) -> Result { - match slice { - x if x.len() != 3 => return Err(IntoColorError::BadLen), - x if x[0] < 0 || x[0] > 255 => return Err(IntoColorError::IntConversion), - x if x[1] < 0 || x[1] > 255 => return Err(IntoColorError::IntConversion), - x if x[2] < 0 || x[2] > 255 => return Err(IntoColorError::IntConversion), - x => Ok(Color {red: x[0] as u8, green: x[1] as u8, blue: x[2] as u8}) - } } } diff --git a/exercises/conversions/using_as.rs b/exercises/conversions/using_as.rs index 97a06d0b..f3f745ff 100644 --- a/exercises/conversions/using_as.rs +++ b/exercises/conversions/using_as.rs @@ -5,9 +5,11 @@ // The goal is to make sure that the division does not fail to compile // and returns the proper type. +// I AM NOT DONE + fn average(values: &[f64]) -> f64 { let total = values.iter().sum::(); - total / values.len() as f64 + total / values.len() } fn main() { diff --git a/exercises/macros/macros1.rs b/exercises/macros/macros1.rs index de2584a5..ed0dac85 100644 --- a/exercises/macros/macros1.rs +++ b/exercises/macros/macros1.rs @@ -1,6 +1,8 @@ // macros1.rs // Make me compile! Execute `rustlings hint macros1` for hints :) +// I AM NOT DONE + macro_rules! my_macro { () => { println!("Check out my macro!"); @@ -8,5 +10,5 @@ macro_rules! my_macro { } fn main() { - my_macro!(); + my_macro(); } diff --git a/exercises/macros/macros2.rs b/exercises/macros/macros2.rs index a9310649..d0be1236 100644 --- a/exercises/macros/macros2.rs +++ b/exercises/macros/macros2.rs @@ -1,12 +1,14 @@ // macros2.rs // Make me compile! Execute `rustlings hint macros2` for hints :) +// I AM NOT DONE + +fn main() { + my_macro!(); +} + macro_rules! my_macro { () => { println!("Check out my macro!"); }; } - -fn main() { - my_macro!(); -} diff --git a/exercises/macros/macros3.rs b/exercises/macros/macros3.rs index 9caa0df7..93a43113 100644 --- a/exercises/macros/macros3.rs +++ b/exercises/macros/macros3.rs @@ -2,8 +2,9 @@ // Make me compile, without taking the macro out of the module! // Execute `rustlings hint macros3` for hints :) +// I AM NOT DONE + mod macros { - #[macro_export] macro_rules! my_macro { () => { println!("Check out my macro!"); diff --git a/exercises/macros/macros4.rs b/exercises/macros/macros4.rs index 5608ecc6..3a748078 100644 --- a/exercises/macros/macros4.rs +++ b/exercises/macros/macros4.rs @@ -1,13 +1,15 @@ // macros4.rs // Make me compile! Execute `rustlings hint macros4` for hints :) +// I AM NOT DONE + macro_rules! my_macro { () => { println!("Check out my macro!"); - }; + } ($val:expr) => { println!("Look at this other macro: {}", $val); - }; + } } fn main() { diff --git a/exercises/quiz4.rs b/exercises/quiz4.rs index 00074975..6c47480d 100644 --- a/exercises/quiz4.rs +++ b/exercises/quiz4.rs @@ -5,11 +5,7 @@ // Write a macro that passes the quiz! No hints this time, you can do it! -macro_rules! my_macro { - ($val:expr) => { - format!("Hello {}", $val) - }; -} +// I AM NOT DONE #[cfg(test)] mod tests { diff --git a/exercises/standard_library_types/iterators5.rs b/exercises/standard_library_types/iterators5.rs index 5fc36ac9..93f3ae11 100644 --- a/exercises/standard_library_types/iterators5.rs +++ b/exercises/standard_library_types/iterators5.rs @@ -10,6 +10,8 @@ // // Make the code compile and the tests pass. +// I AM NOT DONE + use std::collections::HashMap; #[derive(Clone, Copy, PartialEq, Eq)] @@ -32,7 +34,6 @@ fn count_for(map: &HashMap, value: Progress) -> usize { fn count_iterator(map: &HashMap, value: Progress) -> usize { // map is a hashmap with String keys and Progress values. // map = { "variables1": Complete, "from_str": None, ... } - map.values().filter(|item| **item == value).count() } fn count_collection_for(collection: &[HashMap], value: Progress) -> usize { @@ -51,11 +52,6 @@ fn count_collection_iterator(collection: &[HashMap], value: Pr // collection is a slice of hashmaps. // collection = [{ "variables1": Complete, "from_str": None, ... }, // { "variables2": Complete, ... }, ... ] - let result: Option = collection.iter().map(|item| count_iterator(item, value)).reduce(|accum, item| accum + item); - match result { - Some(size) => return size, - None => panic!() - } } #[cfg(test)] diff --git a/exercises/threads/threads1.rs b/exercises/threads/threads1.rs index a75c9fa4..f31b317e 100644 --- a/exercises/threads/threads1.rs +++ b/exercises/threads/threads1.rs @@ -6,7 +6,9 @@ // of "waiting..." and the program ends without timing out when running, // you've got it :) -use std::sync::{Arc, Mutex}; +// I AM NOT DONE + +use std::sync::Arc; use std::thread; use std::time::Duration; @@ -15,17 +17,15 @@ struct JobStatus { } fn main() { - let status = Arc::new(Mutex::new(JobStatus { jobs_completed: 0 })); - let status_shared = Arc::clone(&status); - + let status = Arc::new(JobStatus { jobs_completed: 0 }); + let status_shared = status.clone(); thread::spawn(move || { for _ in 0..10 { thread::sleep(Duration::from_millis(250)); - let mut status_shared = status_shared.lock().unwrap(); status_shared.jobs_completed += 1; } }); - while status.lock().unwrap().jobs_completed < 10 { + while status.jobs_completed < 10 { println!("waiting... "); thread::sleep(Duration::from_millis(500)); } diff --git a/temp_22024_ThreadId1 b/temp_22024_ThreadId1 deleted file mode 100755 index 496bb68a..00000000 Binary files a/temp_22024_ThreadId1 and /dev/null differ