Skip to content

Commit 9acb4e6

Browse files
author
Danilo Krummrich
committed
rust: alloc: layout: implement ArrayLayout::size()
Provide a convenience method for ArrayLayout to calculate the size of the ArrayLayout in bytes. Reviewed-by: Alexandre Courbot <acourbot@nvidia.com> Tested-by: Alexandre Courbot <acourbot@nvidia.com> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Abdiel Janulgue <abdiel.janulgue@gmail.com> Link: https://lore.kernel.org/r/20250820145434.94745-7-dakr@kernel.org Signed-off-by: Danilo Krummrich <dakr@kernel.org>
1 parent 6716184 commit 9acb4e6

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

rust/kernel/alloc/layout.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ impl<T> ArrayLayout<T> {
9898
pub const fn is_empty(&self) -> bool {
9999
self.len == 0
100100
}
101+
102+
/// Returns the size of the [`ArrayLayout`] in bytes.
103+
pub const fn size(&self) -> usize {
104+
self.len() * core::mem::size_of::<T>()
105+
}
101106
}
102107

103108
impl<T> From<ArrayLayout<T>> for Layout {

0 commit comments

Comments
 (0)