Update src/ch04-03-slices.md for formatting

This commit is contained in:
Chris Krycho
2024-12-12 07:53:24 -07:00
committed by GitHub
parent 66ef2b6fcb
commit addb9e1f41

View File

@@ -16,12 +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 dont 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 dont 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.
Lets try that, as shown in Listing 4-7.
The `first_word` function has a `&String` as a parameter. We dont 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 dont 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. Lets 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">