Rename first_word to first_letter

This commit is contained in:
Hugo Masclet
2023-12-25 21:37:03 +01:00
parent 4b4d3453b3
commit 7ac53b8091
2 changed files with 8 additions and 8 deletions

View File

@ -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]
}
```