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 33// TODO: Fix the compiler errors without changing anything except adding or
44// removing references (the character `&`).
55
6- fn main ( ) {
7- let data = "Rust is great!" . to_string ( ) ;
8-
9- get_char ( data) ;
10-
11- string_uppercase ( & data) ;
12- }
13-
146// Shouldn't take ownership
157fn get_char ( data : String ) -> char {
168 data. chars ( ) . last ( ) . unwrap ( )
@@ -22,3 +14,11 @@ fn string_uppercase(mut data: &String) {
2214
2315 println ! ( "{data}" ) ;
2416}
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 11#![ allow( clippy:: ptr_arg) ]
22
3- fn main ( ) {
4- let data = "Rust is great!" . to_string ( ) ;
5-
6- get_char ( & data) ;
7-
8- string_uppercase ( data) ;
9- }
10-
113// Borrows instead of taking ownership.
124// It is recommended to use `&str` instead of `&String` here. But this is
135// enough for now because we didn't handle strings yet.
@@ -21,3 +13,11 @@ fn string_uppercase(mut data: String) {
2113
2214 println ! ( "{data}" ) ;
2315}
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