File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change 1
1
// AsRef and AsMut allow for cheap reference-to-reference conversions.
2
2
// Read more about them at https://doc.rust-lang.org/std/convert/trait.AsRef.html
3
3
// 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.
4
5
5
6
// I AM NOT DONE
6
7
@@ -16,10 +17,10 @@ fn char_counter<T>(arg: T) -> usize {
16
17
arg. as_ref ( ) . chars ( ) . count ( )
17
18
}
18
19
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
+ ???
23
24
}
24
25
25
26
#[ cfg( test) ]
@@ -49,4 +50,11 @@ mod tests {
49
50
let s = String :: from ( "Cafe au lait" ) ;
50
51
assert_eq ! ( char_counter( s. clone( ) ) , byte_counter( s) ) ;
51
52
}
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
+ }
52
60
}
You can’t perform that action at this time.
0 commit comments