book
book copied to clipboard
Kindly add the difference between 'Dangling' Code and the code used while explaining slicing where it was returning the reference.
- [X] I have checked the latest
mainbranch to see if this has already been fixed - [X] I have searched existing issues and pull requests for duplicates
URL to the section(s) of the book with this problem:
Description of the problem:
While reading about Slicing and going through the code with function fn first_word(s: &String) -> &str, the code returns a reference. But while I was learning 'Dangling' I encountered that you can return the value because later the reference of that is of no use as the ownership drops. However, I understood the difference as in the slicing function the input is the reference of the original String and we are just pointing out where the space(b' ') is. But it could cause a bit confused when reading it for the first time.
Suggested fix:
I would suggest mentioning a slight difference between 'Dangling' and fn first_word(s: &String) -> &str function after the latter as it would bring more clarity to the reader.