File tree Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -16,10 +16,12 @@ slices, to understand the problem that slices will solve:
1616fn first_word(s: &String) -> ?
1717```
1818
19- The ` first_word ` function has a ` &String ` as a parameter. We don’t want
20- ownership, so this is fine. But what should we return? We don’t really have a
21- way to talk about _ part_ of a string. However, we could return the index of the
22- end of the word, indicated by a space. Let’s try that, as shown in Listing 4-7.
19+ The ` first_word ` function has a ` &String ` as a parameter. We don’t need
20+ ownership, so this is fine. (In idiomatic Rust, functions do not take ownership
21+ of their arguments unless they need to, and the reasons for that will become
22+ clear as we keep going!) But what should we return? We don’t really have a way
23+ to talk about part of a string. However, we could return the index of the end of
24+ the word, indicated by a space. Let’s try that, as shown in Listing 4-7.
2325
2426<Listing number =" 4-7 " file-name =" src/main.rs " caption =" The `first_word` function that returns a byte index value into the `String` parameter " >
2527
You can’t perform that action at this time.
0 commit comments