pub struct PageSize(/* private fields */);Expand description
A validated page size.
A page size must be a power of two within
MIN_PAGE_SIZE..=MAX_PAGE_SIZE. Validating once, here, means the rest
of the crate can treat the size as a trusted invariant — buffer alignment,
offset arithmetic, and the payload length all rely on it.
§Examples
use page_db::PageSize;
assert!(PageSize::new(8192).is_ok());
assert!(PageSize::new(4096).is_ok());
assert!(PageSize::new(5000).is_err()); // not a power of two
assert!(PageSize::new(1024).is_err()); // below the 4 KiB floorImplementations§
Source§impl PageSize
impl PageSize
Sourcepub const fn new(size: usize) -> PageResult<Self>
pub const fn new(size: usize) -> PageResult<Self>
Validate and wrap a page size in bytes.
§Errors
Returns PageError::InvalidPageSize if size is not a power of two,
or falls outside MIN_PAGE_SIZE..=MAX_PAGE_SIZE.
Sourcepub const fn payload_len(self) -> usize
pub const fn payload_len(self) -> usize
The usable payload length of a page of this size.
Trait Implementations§
impl Copy for PageSize
impl Eq for PageSize
Source§impl Ord for PageSize
impl Ord for PageSize
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
Source§impl PartialOrd for PageSize
impl PartialOrd for PageSize
impl StructuralPartialEq for PageSize
Auto Trait Implementations§
impl Freeze for PageSize
impl RefUnwindSafe for PageSize
impl Send for PageSize
impl Sync for PageSize
impl Unpin for PageSize
impl UnsafeUnpin for PageSize
impl UnwindSafe for PageSize
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