Avoid usage of the unstable Allocator trait

And also optimize init_sections to use the fact that allocate_frames
returns zeroed frames.
This commit is contained in:
bjorn3
2023-12-12 20:32:55 +01:00
committed by Jeremy Soller
parent 5bce3a5bb5
commit 82a87be7d5
2 changed files with 24 additions and 31 deletions
+1 -17
View File
@@ -1,10 +1,3 @@
use core::alloc::Allocator;
use alloc::boxed::Box;
use alloc::vec::Vec;
use crate::memory::Enomem;
pub mod aligned_box;
#[macro_use]
pub mod int_like;
@@ -34,13 +27,4 @@ macro_rules! dbg {
};
}
pub fn try_new_vec_with_exact_size<T, A: Allocator>(len: usize, alloc: A) -> Result<Vec<T, A>, Enomem> {
let mut vec = Vec::<T, A>::new_in(alloc);
vec.try_reserve_exact(len).map_err(|_| Enomem)?;
Ok(vec.into())
}
pub fn try_box_slice_new<T, A: Allocator>(value: impl FnMut() -> T, len: usize, alloc: A) -> Result<Box<[T], A>, Enomem> {
let mut vec = try_new_vec_with_exact_size(len, alloc)?;
vec.resize_with(len, value);
Ok(vec.into())
}