Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. struct IntrusiveNodeObject<T> {
  2. next: *mut IntrusiveNodeObject<T>,
  3. prev: *mut IntrusiveNodeObject<T>,
  4. list: *mut List<T>
  5. }
  6.  
  7. struct List<T> {
  8. root: *mut IntrusiveNodeObject<T>
  9. }
  10.  
  11. impl List<T> {
  12. pub fn push_back(&mut self, item: &mut Pin<Box<IntrusiveNodeObject<T>>>) {
  13. unsafe{
  14. //NOTE: is weakening the &mut to *mut enough to avoid moving out the underlyign value?
  15. let inner = item.as_mut().get_mut();
  16. // NOTE: would be this a problem?
  17. //let mut moved_or_reborrow = &mut *inner_mut_raw;
  18.  
  19. //ERROR, cannot compile: cannot move out of dereference of raw pointer
  20. //let mut moved = *inner_mut_raw;
  21.  
  22. if self.root.is_null() {
  23. inner.next = inner;
  24. inner.prev = inner;
  25.  
  26. self.root = inner;
  27. inner.list = self;
  28. }
  29. }
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement