From 7ac53b8091941ccb1df7f5056fc9bc4b91171b57 Mon Sep 17 00:00:00 2001 From: Hugo Masclet Date: Mon, 25 Dec 2023 21:37:03 +0100 Subject: [PATCH] Rename first_word to first_letter --- en/src/compound-types/slice.md | 8 ++++---- solutions/compound-types/slice.md | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/en/src/compound-types/slice.md b/en/src/compound-types/slice.md index 23aa344..152e61c 100644 --- a/en/src/compound-types/slice.md +++ b/en/src/compound-types/slice.md @@ -84,15 +84,15 @@ fn main() { fn main() { let mut s = String::from("hello world"); - // Here, &s is `&String` type, but `first_word` need a `&str` type. + // Here, &s is `&String` type, but `first_letter` needs a `&str` type. // It works because `&String` can be implicitly converted to `&str. If you want to know more, this is called `Deref coercion`. - let word = first_word(&s); + let letter = first_letter(&s); s.clear(); // error! - println!("the first word is: {}", word); + println!("the first letter is: {}", letter); } -fn first_word(s: &str) -> &str { +fn first_letter(s: &str) -> &str { &s[..1] } ``` diff --git a/solutions/compound-types/slice.md b/solutions/compound-types/slice.md index 32e84cb..371a803 100644 --- a/solutions/compound-types/slice.md +++ b/solutions/compound-types/slice.md @@ -62,16 +62,16 @@ fn main() { fn main() { let mut s = String::from("hello world"); - // here, &s is `&String` type, but `first_word` need a `&str` type. + // here, &s is `&String` type, but `first_letter` needs a `&str` type. // it works because `&String` can be implicitly converted to `&str, If you want know more ,this is called `Deref` - let word = first_word(&s); + let letter = first_letter(&s); - println!("the first word is: {}", word); + println!("the first letter is: {}", letter); s.clear(); } -fn first_word(s: &str) -> &str { +fn first_letter(s: &str) -> &str { &s[..1] } ```