Skip to content

Commit

Permalink
Merge pull request #4074 from spotlesscoder/patch-1
Browse files Browse the repository at this point in the history
fix: make the reason more understandable
  • Loading branch information
chriskrycho authored Dec 12, 2024
2 parents 6f0b1a8 + addb9e1 commit 1521e4e
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/ch04-03-slices.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ slices, to understand the problem that slices will solve:
fn first_word(s: &String) -> ?
```

The `first_word` function has a `&String` as a parameter. We don’t want
ownership, so this is fine. But what should we return? We don’t really have a
way to talk about _part_ of a string. However, we could return the index of the
end of the word, indicated by a space. Let’s try that, as shown in Listing 4-7.
The `first_word` function has a `&String` as a parameter. We don’t need
ownership, so this is fine. (In idiomatic Rust, functions do not take ownership
of their arguments unless they need to, and the reasons for that will become
clear as we keep going!) But what should we return? We don’t really have a way
to talk about part of a string. However, we could return the index of the end of
the word, indicated by a space. Let’s try that, as shown in Listing 4-7.

<Listing number="4-7" file-name="src/main.rs" caption="The `first_word` function that returns a byte index value into the `String` parameter">

Expand Down

0 comments on commit 1521e4e

Please sign in to comment.