add some more code

This commit is contained in:
Charlotte 🦝 Delenk 2022-07-09 12:16:28 +01:00
parent 9747d94ccc
commit 51300ffea4
Signed by: darkkirb
GPG key ID: AB2BD8DAF2E37122

View file

@ -1,6 +1,6 @@
#![no_std]
use tinyptr::ptr::MutPtr;
use tinyptr::ptr::{MutPtr, NonNull};
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct ListNode<const BASE: usize> {
@ -8,3 +8,22 @@ pub struct ListNode<const BASE: usize> {
pub size: u16
}
impl<const BASE: usize> ListNode<BASE> {
pub unsafe fn next(&mut self) -> Option<&mut Self> {
if self.next.is_null() {
None
} else {
Some(&mut *(self.next.wide()))
}
}
pub unsafe fn link_next(&mut self, block: NonNull<Self, BASE>) {
(*block.as_ptr().wide()).next = self.next;
self.next = block.as_ptr();
}
pub unsafe fn unlink_next(&mut self) {
if self.next.is_null() {
return;
}
self.next = (*self.next.wide()).next;
}
}