Skip to content

Non-mut peek? #12

@daschl

Description

@daschl

Hi folks,

I've been poking around in data structures and I need to remove an element from this linked list (it stores a reference of a trait). My code is basically:

pub fn remove(&mut self, timer: &'a T) {
  // other stuff.
        let mut cursor = list.cursor();

        loop {
            let next = cursor.peek_next();
            if next.is_some() {
                if *(next.unwrap()) as *const T == timer as *const T {
                    cursor.remove();
                    break;
                }
                cursor.seek_forward(1);
            } else {
                break;
            }
        }
}

Now this doesn't work because remove and/or seek_forward borrow mut, but the peek_next did already. I think in this case what I'd need would be a peek which doesn't return a mut, right? Can we put that in or is there an obvious solution that I don't know about?

@gankro wdyt?

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