Skip to content

Commit 4bebdb5

Browse files
committed
feat(as_ref_mut): add AsMut section
1 parent 81d25ae commit 4bebdb5

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

exercises/conversions/as_ref_mut.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// AsRef and AsMut allow for cheap reference-to-reference conversions.
22
// Read more about them at https://doc.rust-lang.org/std/convert/trait.AsRef.html
33
// and https://doc.rust-lang.org/std/convert/trait.AsMut.html, respectively.
4+
// Execute `rustlings hint as_ref_mut` or use the `hint` watch subcommand for a hint.
45

56
// I AM NOT DONE
67

@@ -16,10 +17,10 @@ fn char_counter<T>(arg: T) -> usize {
1617
arg.as_ref().chars().count()
1718
}
1819

19-
fn main() {
20-
let s = "Café au lait";
21-
println!("{}", char_counter(s));
22-
println!("{}", byte_counter(s));
20+
// Squares a number using AsMut. Add the trait bound as is appropriate and
21+
// implement the function body.
22+
fn num_sq<T>(arg: &mut T) {
23+
???
2324
}
2425

2526
#[cfg(test)]
@@ -49,4 +50,11 @@ mod tests {
4950
let s = String::from("Cafe au lait");
5051
assert_eq!(char_counter(s.clone()), byte_counter(s));
5152
}
53+
54+
#[test]
55+
fn mult_box() {
56+
let mut num: Box<u32> = Box::new(3);
57+
num_sq(&mut num);
58+
assert_eq!(*num, 9);
59+
}
5260
}

0 commit comments

Comments
 (0)