-
Notifications
You must be signed in to change notification settings - Fork 12
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
Non-mut peek? #12
Comments
I think I was able to work around it by doing let pos = list.iter()
.position(|t| *t as *const T == timer as *const T)
.expect("Position not found!");
list.remove(pos); But if I'm not mistaken that in the worst case involves 2 full seeks instead of 1 so its O(2n), right? |
You can't call enum Action {
Remove,
SeekForward,
}
loop {
let action = match cursor.peek_next() {
Some(t) =>
if *t as *const T == timer as *const T {
Action::Remove
} else {
Action::SeekForward
},
None => break,
};
match action {
Action::Remove => {
cursor.remove();
break;
}
Action::SeekForward => cursor.seek_forward(1),
}
} |
@apasel422 would it make sense to add a remove method to it? And thanks for the example clarification! |
I think you can simply do this:
|
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:
Now this doesn't work because
remove
and/orseek_forward
borrow mut, but thepeek_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?
The text was updated successfully, but these errors were encountered: