rust: alloc: introduce ArrayLayout
When allocating memory for arrays using allocators, the `Layout::array` function is typically used. It returns a result, since the given size might be too big. However, `Vec` and its iterators store their allocated capacity and thus they already did check that the size is not too big. The `ArrayLayout` type provides this exact behavior, as it can be infallibly converted into a `Layout`. Instead of a `usize` capacity, `Vec` and other similar array-storing types can use `ArrayLayout` instead. Reviewed-by: Gary Guo <gary@garyguo.net> Signed-off-by: Benno Lossin <benno.lossin@proton.me> Signed-off-by: Danilo Krummrich <dakr@kernel.org> Link: https://lore.kernel.org/r/20241004154149.93856-16-dakr@kernel.org [ Formatted a few comments. - Miguel ] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
This commit is contained in:
committed by
Miguel Ojeda
parent
e1044c2238
commit
9e7bbfa182
@@ -5,6 +5,7 @@
|
||||
#[cfg(not(any(test, testlib)))]
|
||||
pub mod allocator;
|
||||
pub mod kbox;
|
||||
pub mod layout;
|
||||
pub mod vec_ext;
|
||||
|
||||
#[cfg(any(test, testlib))]
|
||||
|
||||
Reference in New Issue
Block a user