pub struct GenericBlockSize<T: BlockSizeSpec>(/* private fields */);Expand description
Represents a block size that is a power of 2, parameterized by a BlockSizeSpec.
Provides zero-cost bitwise operations for alignments, conversions, and arithmetic with integers.
Implementations§
Source§impl<T: BlockSizeSpec> GenericBlockSize<T>
impl<T: BlockSizeSpec> GenericBlockSize<T>
pub fn from_spec(spec: T) -> Self
Sourcepub fn is_aligned(self, value: impl IsAligned<T>) -> bool
pub fn is_aligned(self, value: impl IsAligned<T>) -> bool
Returns true if value is aligned to this block size.
Sourcepub fn align_up(self, bytes: u64) -> Option<u64>
pub fn align_up(self, bytes: u64) -> Option<u64>
Aligns bytes up to the nearest block boundary, returning None on overflow.
Sourcepub fn align_down(self, bytes: u64) -> u64
pub fn align_down(self, bytes: u64) -> u64
Aligns bytes down to the nearest block boundary.
Sourcepub fn align_up_to_blocks(self, bytes: u64) -> u64
pub fn align_up_to_blocks(self, bytes: u64) -> u64
Aligns bytes up to the nearest block boundary and returns the total number of blocks.
Source§impl GenericBlockSize<MaskShiftSpec>
impl GenericBlockSize<MaskShiftSpec>
pub const SIZE_512B: Self
pub const SIZE_1KIB: Self
pub const SIZE_2KIB: Self
pub const SIZE_4KIB: Self
pub const SIZE_8KIB: Self
pub const SIZE_16KIB: Self
pub const SIZE_32KIB: Self
pub const SIZE_64KIB: Self
pub const SIZE_128KIB: Self
pub const SIZE_256KIB: Self
pub const SIZE_512KIB: Self
pub const SIZE_1MIB: Self
Sourcepub const fn new(block_size: u32) -> Option<Self>
pub const fn new(block_size: u32) -> Option<Self>
Constructs a BlockSize from a u32 byte count if it is a power of 2 and not equal to 0.
Trait Implementations§
Source§impl<T: BlockSizeSpec> Add<&GenericBlockSize<T>> for u64
impl<T: BlockSizeSpec> Add<&GenericBlockSize<T>> for u64
Source§impl<T: BlockSizeSpec> Add<&GenericBlockSize<T>> for &u64
impl<T: BlockSizeSpec> Add<&GenericBlockSize<T>> for &u64
Source§impl<T: BlockSizeSpec> Add<&u64> for GenericBlockSize<T>
impl<T: BlockSizeSpec> Add<&u64> for GenericBlockSize<T>
Source§impl<T: BlockSizeSpec> Add<&u64> for &GenericBlockSize<T>
impl<T: BlockSizeSpec> Add<&u64> for &GenericBlockSize<T>
Source§impl<T: BlockSizeSpec> Add<GenericBlockSize<T>> for u64
impl<T: BlockSizeSpec> Add<GenericBlockSize<T>> for u64
Source§impl<T: BlockSizeSpec> Add<GenericBlockSize<T>> for &u64
impl<T: BlockSizeSpec> Add<GenericBlockSize<T>> for &u64
Source§impl<T: BlockSizeSpec> Add<u64> for GenericBlockSize<T>
impl<T: BlockSizeSpec> Add<u64> for GenericBlockSize<T>
Source§impl<T: BlockSizeSpec> Add<u64> for &GenericBlockSize<T>
impl<T: BlockSizeSpec> Add<u64> for &GenericBlockSize<T>
Source§impl<T: BlockSizeSpec> AddAssign<&GenericBlockSize<T>> for u64
impl<T: BlockSizeSpec> AddAssign<&GenericBlockSize<T>> for u64
Source§fn add_assign(&mut self, other: &GenericBlockSize<T>)
fn add_assign(&mut self, other: &GenericBlockSize<T>)
Performs the
+= operation. Read moreSource§impl<T: BlockSizeSpec> AddAssign<GenericBlockSize<T>> for u64
impl<T: BlockSizeSpec> AddAssign<GenericBlockSize<T>> for u64
Source§fn add_assign(&mut self, other: GenericBlockSize<T>)
fn add_assign(&mut self, other: GenericBlockSize<T>)
Performs the
+= operation. Read moreSource§impl<T: BlockSizeSpec> Binary for GenericBlockSize<T>
impl<T: BlockSizeSpec> Binary for GenericBlockSize<T>
Source§impl<T: Clone + BlockSizeSpec> Clone for GenericBlockSize<T>
impl<T: Clone + BlockSizeSpec> Clone for GenericBlockSize<T>
Source§fn clone(&self) -> GenericBlockSize<T>
fn clone(&self) -> GenericBlockSize<T>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl<T: Copy + BlockSizeSpec> Copy for GenericBlockSize<T>
Source§impl<T: Debug + BlockSizeSpec> Debug for GenericBlockSize<T>
impl<T: Debug + BlockSizeSpec> Debug for GenericBlockSize<T>
Source§impl<T: BlockSizeSpec> Display for GenericBlockSize<T>
impl<T: BlockSizeSpec> Display for GenericBlockSize<T>
Source§impl<T: BlockSizeSpec> Div<&GenericBlockSize<T>> for u64
impl<T: BlockSizeSpec> Div<&GenericBlockSize<T>> for u64
Source§impl<T: BlockSizeSpec> Div<&GenericBlockSize<T>> for &u64
impl<T: BlockSizeSpec> Div<&GenericBlockSize<T>> for &u64
Source§impl<T: BlockSizeSpec> Div<GenericBlockSize<T>> for u64
impl<T: BlockSizeSpec> Div<GenericBlockSize<T>> for u64
Source§impl<T: BlockSizeSpec> Div<GenericBlockSize<T>> for &u64
impl<T: BlockSizeSpec> Div<GenericBlockSize<T>> for &u64
Source§impl<T: BlockSizeSpec> DivAssign<&GenericBlockSize<T>> for u64
impl<T: BlockSizeSpec> DivAssign<&GenericBlockSize<T>> for u64
Source§fn div_assign(&mut self, other: &GenericBlockSize<T>)
fn div_assign(&mut self, other: &GenericBlockSize<T>)
Performs the
/= operation. Read moreSource§impl<T: BlockSizeSpec> DivAssign<GenericBlockSize<T>> for u64
impl<T: BlockSizeSpec> DivAssign<GenericBlockSize<T>> for u64
Source§fn div_assign(&mut self, other: GenericBlockSize<T>)
fn div_assign(&mut self, other: GenericBlockSize<T>)
Performs the
/= operation. Read moreimpl<T: Eq + BlockSizeSpec> Eq for GenericBlockSize<T>
Source§impl From<GenericBlockSize<PageSizeSpec>> for BlockSize
impl From<GenericBlockSize<PageSizeSpec>> for BlockSize
Source§fn from(_value: GenericBlockSize<PageSizeSpec>) -> Self
fn from(_value: GenericBlockSize<PageSizeSpec>) -> Self
Converts to this type from the input type.
Source§impl<T: BlockSizeSpec> Hash for GenericBlockSize<T>
impl<T: BlockSizeSpec> Hash for GenericBlockSize<T>
Source§impl<T: BlockSizeSpec> LowerHex for GenericBlockSize<T>
impl<T: BlockSizeSpec> LowerHex for GenericBlockSize<T>
Source§impl<T: BlockSizeSpec> Mul<&GenericBlockSize<T>> for u64
impl<T: BlockSizeSpec> Mul<&GenericBlockSize<T>> for u64
Source§impl<T: BlockSizeSpec> Mul<&GenericBlockSize<T>> for &u64
impl<T: BlockSizeSpec> Mul<&GenericBlockSize<T>> for &u64
Source§impl<T: BlockSizeSpec> Mul<&u64> for GenericBlockSize<T>
impl<T: BlockSizeSpec> Mul<&u64> for GenericBlockSize<T>
Source§impl<T: BlockSizeSpec> Mul<&u64> for &GenericBlockSize<T>
impl<T: BlockSizeSpec> Mul<&u64> for &GenericBlockSize<T>
Source§impl<T: BlockSizeSpec> Mul<GenericBlockSize<T>> for u64
impl<T: BlockSizeSpec> Mul<GenericBlockSize<T>> for u64
Source§impl<T: BlockSizeSpec> Mul<GenericBlockSize<T>> for &u64
impl<T: BlockSizeSpec> Mul<GenericBlockSize<T>> for &u64
Source§impl<T: BlockSizeSpec> Mul<u64> for GenericBlockSize<T>
impl<T: BlockSizeSpec> Mul<u64> for GenericBlockSize<T>
Source§impl<T: BlockSizeSpec> Mul<u64> for &GenericBlockSize<T>
impl<T: BlockSizeSpec> Mul<u64> for &GenericBlockSize<T>
Source§impl<T: BlockSizeSpec> MulAssign<&GenericBlockSize<T>> for u64
impl<T: BlockSizeSpec> MulAssign<&GenericBlockSize<T>> for u64
Source§fn mul_assign(&mut self, other: &GenericBlockSize<T>)
fn mul_assign(&mut self, other: &GenericBlockSize<T>)
Performs the
*= operation. Read moreSource§impl<T: BlockSizeSpec> MulAssign<GenericBlockSize<T>> for u64
impl<T: BlockSizeSpec> MulAssign<GenericBlockSize<T>> for u64
Source§fn mul_assign(&mut self, other: GenericBlockSize<T>)
fn mul_assign(&mut self, other: GenericBlockSize<T>)
Performs the
*= operation. Read moreSource§impl<T: BlockSizeSpec> Octal for GenericBlockSize<T>
impl<T: BlockSizeSpec> Octal for GenericBlockSize<T>
Source§impl<T: BlockSizeSpec> Ord for GenericBlockSize<T>
impl<T: BlockSizeSpec> Ord for GenericBlockSize<T>
1.21.0 (const: unstable) · 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
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl<T: BlockSizeSpec> PartialEq<&GenericBlockSize<T>> for u64
impl<T: BlockSizeSpec> PartialEq<&GenericBlockSize<T>> for u64
Source§impl<T: BlockSizeSpec> PartialEq<&u64> for GenericBlockSize<T>
impl<T: BlockSizeSpec> PartialEq<&u64> for GenericBlockSize<T>
Source§impl<T: BlockSizeSpec> PartialEq<GenericBlockSize<T>> for u64
impl<T: BlockSizeSpec> PartialEq<GenericBlockSize<T>> for u64
Source§impl<T: BlockSizeSpec> PartialEq<GenericBlockSize<T>> for &u64
impl<T: BlockSizeSpec> PartialEq<GenericBlockSize<T>> for &u64
Source§impl<T: BlockSizeSpec, U: BlockSizeSpec> PartialEq<GenericBlockSize<T>> for GenericBlockSize<U>
impl<T: BlockSizeSpec, U: BlockSizeSpec> PartialEq<GenericBlockSize<T>> for GenericBlockSize<U>
Source§impl<T: BlockSizeSpec> PartialEq<u64> for GenericBlockSize<T>
impl<T: BlockSizeSpec> PartialEq<u64> for GenericBlockSize<T>
Source§impl<T: BlockSizeSpec> PartialEq<u64> for &GenericBlockSize<T>
impl<T: BlockSizeSpec> PartialEq<u64> for &GenericBlockSize<T>
Source§impl<T: BlockSizeSpec> PartialOrd<&GenericBlockSize<T>> for u64
impl<T: BlockSizeSpec> PartialOrd<&GenericBlockSize<T>> for u64
Source§impl<T: BlockSizeSpec> PartialOrd<&u64> for GenericBlockSize<T>
impl<T: BlockSizeSpec> PartialOrd<&u64> for GenericBlockSize<T>
Source§impl<T: BlockSizeSpec> PartialOrd<GenericBlockSize<T>> for u64
impl<T: BlockSizeSpec> PartialOrd<GenericBlockSize<T>> for u64
Source§impl<T: BlockSizeSpec> PartialOrd<GenericBlockSize<T>> for &u64
impl<T: BlockSizeSpec> PartialOrd<GenericBlockSize<T>> for &u64
Source§impl<T: BlockSizeSpec, U: BlockSizeSpec> PartialOrd<GenericBlockSize<T>> for GenericBlockSize<U>
impl<T: BlockSizeSpec, U: BlockSizeSpec> PartialOrd<GenericBlockSize<T>> for GenericBlockSize<U>
Source§impl<T: BlockSizeSpec> PartialOrd<u64> for GenericBlockSize<T>
impl<T: BlockSizeSpec> PartialOrd<u64> for GenericBlockSize<T>
Source§impl<T: BlockSizeSpec> PartialOrd<u64> for &GenericBlockSize<T>
impl<T: BlockSizeSpec> PartialOrd<u64> for &GenericBlockSize<T>
Source§impl<T: BlockSizeSpec> Rem<&GenericBlockSize<T>> for u64
impl<T: BlockSizeSpec> Rem<&GenericBlockSize<T>> for u64
Source§impl<T: BlockSizeSpec> Rem<&GenericBlockSize<T>> for &u64
impl<T: BlockSizeSpec> Rem<&GenericBlockSize<T>> for &u64
Source§impl<T: BlockSizeSpec> Rem<GenericBlockSize<T>> for u64
impl<T: BlockSizeSpec> Rem<GenericBlockSize<T>> for u64
Source§impl<T: BlockSizeSpec> Rem<GenericBlockSize<T>> for &u64
impl<T: BlockSizeSpec> Rem<GenericBlockSize<T>> for &u64
Source§impl<T: BlockSizeSpec> RemAssign<&GenericBlockSize<T>> for u64
impl<T: BlockSizeSpec> RemAssign<&GenericBlockSize<T>> for u64
Source§fn rem_assign(&mut self, other: &GenericBlockSize<T>)
fn rem_assign(&mut self, other: &GenericBlockSize<T>)
Performs the
%= operation. Read moreSource§impl<T: BlockSizeSpec> RemAssign<GenericBlockSize<T>> for u64
impl<T: BlockSizeSpec> RemAssign<GenericBlockSize<T>> for u64
Source§fn rem_assign(&mut self, other: GenericBlockSize<T>)
fn rem_assign(&mut self, other: GenericBlockSize<T>)
Performs the
%= operation. Read moreSource§impl<T: BlockSizeSpec> Sub<&GenericBlockSize<T>> for u64
impl<T: BlockSizeSpec> Sub<&GenericBlockSize<T>> for u64
Source§impl<T: BlockSizeSpec> Sub<&GenericBlockSize<T>> for &u64
impl<T: BlockSizeSpec> Sub<&GenericBlockSize<T>> for &u64
Source§impl<T: BlockSizeSpec> Sub<&u64> for GenericBlockSize<T>
impl<T: BlockSizeSpec> Sub<&u64> for GenericBlockSize<T>
Source§impl<T: BlockSizeSpec> Sub<&u64> for &GenericBlockSize<T>
impl<T: BlockSizeSpec> Sub<&u64> for &GenericBlockSize<T>
Source§impl<T: BlockSizeSpec> Sub<GenericBlockSize<T>> for u64
impl<T: BlockSizeSpec> Sub<GenericBlockSize<T>> for u64
Source§impl<T: BlockSizeSpec> Sub<GenericBlockSize<T>> for &u64
impl<T: BlockSizeSpec> Sub<GenericBlockSize<T>> for &u64
Source§impl<T: BlockSizeSpec> Sub<u64> for GenericBlockSize<T>
impl<T: BlockSizeSpec> Sub<u64> for GenericBlockSize<T>
Source§impl<T: BlockSizeSpec> Sub<u64> for &GenericBlockSize<T>
impl<T: BlockSizeSpec> Sub<u64> for &GenericBlockSize<T>
Source§impl<T: BlockSizeSpec> SubAssign<&GenericBlockSize<T>> for u64
impl<T: BlockSizeSpec> SubAssign<&GenericBlockSize<T>> for u64
Source§fn sub_assign(&mut self, other: &GenericBlockSize<T>)
fn sub_assign(&mut self, other: &GenericBlockSize<T>)
Performs the
-= operation. Read moreSource§impl<T: BlockSizeSpec> SubAssign<GenericBlockSize<T>> for u64
impl<T: BlockSizeSpec> SubAssign<GenericBlockSize<T>> for u64
Source§fn sub_assign(&mut self, other: GenericBlockSize<T>)
fn sub_assign(&mut self, other: GenericBlockSize<T>)
Performs the
-= operation. Read moreAuto Trait Implementations§
impl<T> Freeze for GenericBlockSize<T>where
T: Freeze,
impl<T> RefUnwindSafe for GenericBlockSize<T>where
T: RefUnwindSafe,
impl<T> Send for GenericBlockSize<T>where
T: Send,
impl<T> Sync for GenericBlockSize<T>where
T: Sync,
impl<T> Unpin for GenericBlockSize<T>where
T: Unpin,
impl<T> UnsafeUnpin for GenericBlockSize<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for GenericBlockSize<T>where
T: UnwindSafe,
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