pub struct Allocation {
pub offset: u32,
pub size: NonZero<u32>,
}
Expand description
Metadata containing information about an allocation
This is a small Copy
type. It also provides a niche, so that
Option<Allocation>
has the same size as Allocation
.
assert_eq!(size_of::<Allocation>(), size_of::<u64>());
assert_eq!(size_of::<Option<Allocation>>(), size_of::<Allocation>());
Fields§
§offset: u32
The location of this allocation within the buffer
size: NonZero<u32>
The size of this allocation
Implementations§
Source§impl Allocation
impl Allocation
Sourcepub fn offset(&self) -> u32
pub fn offset(&self) -> u32
Get the offset of the allocation
This is just a wrapper for allocation.offset
for symmetry with size
.
Sourcepub fn size(&self) -> u32
pub fn size(&self) -> u32
Get the size of the allocation
This is just sugar for allocation.size.get()
.
Sourcepub fn range(&self) -> Range<usize>
pub fn range(&self) -> Range<usize>
Get a Range<usize>
from offset
to offset + size
This can be used to directly index a buffer.
For example:
ⓘ
let buffer: Vec<usize> = (0..100).collect();
let allocation = Allocation {
offset: 25,
size: NonZero::new(4).unwrap()
};
let region = &buffer[allocation.range()];
assert_eq!(region, &[25, 26, 27, 28]);
Trait Implementations§
Source§impl Clone for Allocation
impl Clone for Allocation
Source§fn clone(&self) -> Allocation
fn clone(&self) -> Allocation
Returns a duplicate of the value. Read more
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for Allocation
impl Debug for Allocation
Source§impl Hash for Allocation
impl Hash for Allocation
Source§impl Ord for Allocation
impl Ord for Allocation
Source§fn cmp(&self, other: &Allocation) -> Ordering
fn cmp(&self, other: &Allocation) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialEq for Allocation
impl PartialEq for Allocation
Source§impl PartialOrd for Allocation
impl PartialOrd for Allocation
impl Copy for Allocation
impl Eq for Allocation
impl StructuralPartialEq for Allocation
Auto Trait Implementations§
impl Freeze for Allocation
impl RefUnwindSafe for Allocation
impl Send for Allocation
impl Sync for Allocation
impl Unpin for Allocation
impl UnwindSafe for Allocation
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more