Getting a mutable reference from CursorMut in LinkedList
brianshih1 opened this issue · comments
Brian Shih commented
Hello I am trying to get a mutable reference to the last element in the linked list. Since there is no get_mut()
on a CursorMut
, I currently have to remove the final element of the LinkedList, modify it, then push it back onto the Linked list:
let mut last_fragment = self.frags.back_mut();
let mut last_fragment = last_fragment.remove().unwrap();
last_fragment.as_mut().append(src, len);
self.frags.push_back(last_fragment);
Is there a better way to do this? Thanks!
Amanieu d'Antras commented
You can put your data in a Cell
, RefCell
or UnsafeCell
so that you can modify it with only get
.
Brian Shih commented
got it, makes sense!