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

feat(#25): impl Iterator for LinkedList #25

Closed
wants to merge 0 commits into from
Closed

feat(#25): impl Iterator for LinkedList #25

wants to merge 0 commits into from

Conversation

kul-sudo
Copy link
Contributor

@kul-sudo kul-sudo commented Aug 2, 2024

No description provided.

@slbsh slbsh changed the title chore: Add Iterator trait for LinkedList feat(#25): impl IntoIterator for LinkedList Aug 2, 2024
@slbsh slbsh changed the title feat(#25): impl IntoIterator for LinkedList feat(#25): impl Iterator for LinkedList Aug 2, 2024
@slbsh
Copy link
Member

slbsh commented Aug 2, 2024

dont make a LinkedList the iterator, instead make a new type:

impl<T> LinkedList<T> {
    pub fn iter(&self) -> Iter<'_, T> {
        Iter { node: self.front, len: self.len, _boo: PhantomData }
    }
}

pub struct Iter<'l, T> {
    node: Link<T>,
    len:  usize,
    _boo: PhantomData<&'l Node<T>>,
}

impl<T> Iterator for Iter<'l, T> {
    type Item = &'l T;

    fn next(&mut self) -> Option<&'l T> {
        /* do the logic */
    }
}

@kul-sudo kul-sudo closed this Aug 4, 2024
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

Successfully merging this pull request may close these issues.

2 participants