diff --git a/exercises/conversions/as_ref_mut.rs b/exercises/conversions/as_ref_mut.rs index 84f4a60..9f47973 100644 --- a/exercises/conversions/as_ref_mut.rs +++ b/exercises/conversions/as_ref_mut.rs @@ -1,6 +1,7 @@ // AsRef and AsMut allow for cheap reference-to-reference conversions. // 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. +// Execute `rustlings hint as_ref_mut` or use the `hint` watch subcommand for a hint. // I AM NOT DONE @@ -16,10 +17,10 @@ fn char_counter(arg: T) -> usize { arg.as_ref().chars().count() } -fn main() { - let s = "Café au lait"; - println!("{}", char_counter(s)); - println!("{}", byte_counter(s)); +// Squares a number using AsMut. Add the trait bound as is appropriate and +// implement the function body. +fn num_sq(arg: &mut T) { + ??? } #[cfg(test)] @@ -49,4 +50,11 @@ mod tests { let s = String::from("Cafe au lait"); assert_eq!(char_counter(s.clone()), byte_counter(s)); } + + #[test] + fn mult_box() { + let mut num: Box = Box::new(3); + num_sq(&mut num); + assert_eq!(*num, 9); + } }