From 51300ffea41161cd875567b11bfc9414f6cd952b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charlotte=20=F0=9F=A6=9D=20Delenk?= Date: Sat, 9 Jul 2022 12:16:28 +0100 Subject: [PATCH] add some more code --- lib/tinyptr-alloc/src/lib.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/tinyptr-alloc/src/lib.rs b/lib/tinyptr-alloc/src/lib.rs index b7c2b75..1ae8657 100644 --- a/lib/tinyptr-alloc/src/lib.rs +++ b/lib/tinyptr-alloc/src/lib.rs @@ -1,6 +1,6 @@ #![no_std] -use tinyptr::ptr::MutPtr; +use tinyptr::ptr::{MutPtr, NonNull}; #[derive(Copy, Clone, Debug, PartialEq, Eq)] pub struct ListNode { @@ -8,3 +8,22 @@ pub struct ListNode { pub size: u16 } +impl ListNode { + 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) { + (*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; + } +}