From 21b4dd14b696420c157192b311dd1f998a58ce88 Mon Sep 17 00:00:00 2001 From: laazy Date: Sat, 23 Mar 2024 23:24:12 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20complete=20last=20one?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- exercises/23_conversions/as_ref_mut.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/exercises/23_conversions/as_ref_mut.rs b/exercises/23_conversions/as_ref_mut.rs index 5eb8cd6f..ed53b957 100644 --- a/exercises/23_conversions/as_ref_mut.rs +++ b/exercises/23_conversions/as_ref_mut.rs @@ -7,12 +7,10 @@ // Execute `rustlings hint as_ref_mut` or use the `hint` watch subcommand for a // hint. -// I AM NOT DONE +use std::ops::DerefMut; -use std::ops::Mul; // Obtain the number of bytes (not characters) in the given argument. -// TODO: Add the AsRef trait appropriately as a trait bound. fn byte_counter(arg: T) -> usize where T: AsRef { @@ -20,7 +18,6 @@ where T: AsRef } // Obtain the number of characters (not bytes) in the given argument. -// TODO: Add the AsRef trait appropriately as a trait bound. fn char_counter(arg: T) -> usize where T: AsRef { @@ -29,11 +26,12 @@ where T: AsRef // Squares a number using as_mut(). // TODO: Add the appropriate trait bound. -fn num_sq(arg: &mut T) -where T: for<'a> AsMut<&'a mut Box> + for<'a> Mul<&'a mut T, Output = T>// + std::ops::MulAssign<&mut Box> +fn num_sq(arg: &mut T) +// where T: DerefMut, +where T: AsMut { // TODO: Implement the function body. - *arg = (*arg) * arg; + *arg.as_mut() = *arg.as_mut() * *arg.as_mut(); } #[cfg(test)]