File tree Expand file tree Collapse file tree 2 files changed +16
-16
lines changed
exercises/06_move_semantics
solutions/06_move_semantics Expand file tree Collapse file tree 2 files changed +16
-16
lines changed Original file line number Diff line number Diff line change 3
3
// TODO: Fix the compiler errors without changing anything except adding or
4
4
// removing references (the character `&`).
5
5
6
- fn main ( ) {
7
- let data = "Rust is great!" . to_string ( ) ;
8
-
9
- get_char ( data) ;
10
-
11
- string_uppercase ( & data) ;
12
- }
13
-
14
6
// Shouldn't take ownership
15
7
fn get_char ( data : String ) -> char {
16
8
data. chars ( ) . last ( ) . unwrap ( )
@@ -22,3 +14,11 @@ fn string_uppercase(mut data: &String) {
22
14
23
15
println ! ( "{data}" ) ;
24
16
}
17
+
18
+ fn main ( ) {
19
+ let data = "Rust is great!" . to_string ( ) ;
20
+
21
+ get_char ( data) ;
22
+
23
+ string_uppercase ( & data) ;
24
+ }
Original file line number Diff line number Diff line change 1
1
#![ allow( clippy:: ptr_arg) ]
2
2
3
- fn main ( ) {
4
- let data = "Rust is great!" . to_string ( ) ;
5
-
6
- get_char ( & data) ;
7
-
8
- string_uppercase ( data) ;
9
- }
10
-
11
3
// Borrows instead of taking ownership.
12
4
// It is recommended to use `&str` instead of `&String` here. But this is
13
5
// enough for now because we didn't handle strings yet.
@@ -21,3 +13,11 @@ fn string_uppercase(mut data: String) {
21
13
22
14
println ! ( "{data}" ) ;
23
15
}
16
+
17
+ fn main ( ) {
18
+ let data = "Rust is great!" . to_string ( ) ;
19
+
20
+ get_char ( & data) ;
21
+
22
+ string_uppercase ( data) ;
23
+ }
You can’t perform that action at this time.
0 commit comments