Amanieu / intrusive-rs

Intrusive collections for Rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Getting a mutable reference from CursorMut in LinkedList

brianshih1 opened this issue · comments

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!

You can put your data in a Cell, RefCell or UnsafeCell so that you can modify it with only get.

got it, makes sense!