Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify important implicit lifetime choice for Iter #313

Open
sancho20021 opened this issue Jan 20, 2025 · 0 comments
Open

Clarify important implicit lifetime choice for Iter #313

sancho20021 opened this issue Jan 20, 2025 · 0 comments

Comments

@sancho20021
Copy link

https://rust-unofficial.github.io/too-many-lists/sixth-combinatorics.html
Here you implement Iter for the linked list assuming it will work, and it works. Good!
But the reader might wonder what is the role of the lifetime 'a? Indeed, we do not see any explicit uses of it except PhantomData.

The use is hidden in the signature of fn iter(&self) -> Iter<T>. We could change it to fn iter<'s>(&self) -> Iter<'s, T> and everything will go wrong as now iterator won't borrow linked list and could be iterated after list's destruction.
I guess this is why we need lifetimes but it is not explained in the section.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant