Code cleanup
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user