From 26f571b0809512d569cb7f07ff6c3846e1ea7fe8 Mon Sep 17 00:00:00 2001 From: spotlesscoder Date: Wed, 16 Oct 2024 07:57:04 +0200 Subject: [PATCH 1/2] fix: make the reason more understandable --- src/ch04-03-slices.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch04-03-slices.md b/src/ch04-03-slices.md index d01d905021..c9c97ed7a2 100644 --- a/src/ch04-03-slices.md +++ b/src/ch04-03-slices.md @@ -17,7 +17,7 @@ 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 +ownership because we want to keep using the `String` after calling the `first_word` function, 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. From addb9e1f4101e84ed963daa0936c73ecc5d07fbb Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 12 Dec 2024 07:53:24 -0700 Subject: [PATCH 2/2] Update src/ch04-03-slices.md for formatting --- src/ch04-03-slices.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ch04-03-slices.md b/src/ch04-03-slices.md index 44c7f00b68..440653e430 100644 --- a/src/ch04-03-slices.md +++ b/src/ch04-03-slices.md @@ -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 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. +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.