Skip to content

Commit 1521e4e

Browse files
authored
Merge pull request #4074 from spotlesscoder/patch-1
fix: make the reason more understandable
2 parents 6f0b1a8 + addb9e1 commit 1521e4e

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/ch04-03-slices.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ slices, to understand the problem that slices will solve:
1616
fn 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

0 commit comments

Comments
 (0)