Skip to content

Clarify important implicit lifetime choice for Iter #313

Description

@sancho20021

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions