Code cleanup

This commit is contained in:
Mia
2026-03-06 15:28:30 +01:00
parent bd0b619127
commit 92c02c6ca2
9 changed files with 63 additions and 68 deletions
+6 -2
View File
@@ -17,7 +17,10 @@ unsafe impl Send for AllocationEntry {}
unsafe impl Sync for AllocationEntry {}
pub trait Allocator {
#[allow(clippy::missing_safety_doc)]
unsafe fn alloc_uninit(&self, layout: Layout, drop: DropFn) -> *mut u8;
#[allow(clippy::missing_safety_doc)]
unsafe fn alloc_unsafe(&self, data: *const u8, layout: Layout, drop: DropFn) -> *mut u8;
}
@@ -26,6 +29,7 @@ pub trait SyncAllocator: Allocator + Send + Sync {}
impl<T: Allocator + Send + Sync> SyncAllocator for T {}
impl<'l> dyn Allocator + 'l {
#[allow(clippy::mut_from_ref)]
pub fn alloc<T>(&'l self, value: T) -> &'l mut T {
unsafe {
let value = MaybeUninit::new(value);
@@ -49,7 +53,7 @@ impl<'l> dyn Allocator + 'l {
}
}
pub fn alloc_slice<T>(&'l self, iter: impl Iterator<Item = T> + ExactSizeIterator) -> &'l [T] {
pub fn alloc_slice<T>(&'l self, iter: impl ExactSizeIterator<Item = T>) -> &'l [T] {
unsafe {
let len = iter.len();
let layout = Layout::array::<T>(len).unwrap();
@@ -82,7 +86,7 @@ impl<'l> dyn SyncAllocator + 'l {
<dyn Allocator>::alloc_str(self, value)
}
pub fn alloc_slice<T>(&'l self, iter: impl Iterator<Item = T> + ExactSizeIterator) -> &'l [T] {
pub fn alloc_slice<T>(&'l self, iter: impl ExactSizeIterator<Item = T>) -> &'l [T] {
<dyn Allocator>::alloc_slice(self, iter)
}
}