diff --git a/exercises/conversions/as_ref_mut.rs b/exercises/conversions/as_ref_mut.rs index c9eed7d0..771a9bbf 100644 --- a/exercises/conversions/as_ref_mut.rs +++ b/exercises/conversions/as_ref_mut.rs @@ -3,24 +3,25 @@ // and https://doc.rust-lang.org/std/convert/trait.AsMut.html, respectively. // Execute `rustlings hint as_ref_mut` or use the `hint` watch subcommand for a hint. -// 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 +where + T: AsRef, +{ 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() } // Squares a number using as_mut(). Add the trait bound as is appropriate and // implement the function body. -fn num_sq(arg: &mut T) { - ??? +fn num_sq>(arg: &mut T) { + *arg.as_mut() = arg.as_mut().pow(2); } #[cfg(test)] diff --git a/exercises/conversions/try_from_into.rs b/exercises/conversions/try_from_into.rs index 21f56fbc..4485b90d 100644 --- a/exercises/conversions/try_from_into.rs +++ b/exercises/conversions/try_from_into.rs @@ -62,14 +62,6 @@ impl TryFrom<[i16; 3]> for Color { type Error = IntoColorError; fn try_from(arr: [i16; 3]) -> Result { let mut a: [u8; 3] = [0, 0, 0]; - // arr.into_iter().enumerate().map(|(i, x)| { - // let t: u8 = match x.try_into() { - // Ok(i) => i, - // Err(err) => { - // return Err(IntoColorError::IntConversion); - // } - // }; - // }); for (i, x) in arr.into_iter().enumerate() { let tmp: u8 = match x.to_owned().try_into() { Ok(i) => i,