File tree 1 file changed +6
-4
lines changed
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:
16
16
fn first_word(s: &String) -> ?
17
17
```
18
18
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.
23
25
24
26
<Listing number =" 4-7 " file-name =" src/main.rs " caption =" The `first_word` function that returns a byte index value into the `String` parameter " >
25
27
You can’t perform that action at this time.
0 commit comments