pub struct Length { /* private fields */ }
Expand description
Represents length internally used by osom tools. Unlike Rust usize
type, the Length
type is a thin wrapper around u32
. In particular
it is 32-bit on 64-bit machines. While limiting, the osom libs won’t
be using such big arrays anyway. And it saves us space.
Implementations§
Source§impl Length
impl Length
Sourcepub const SAFE_MARGIN: u32 = 2_048u32
pub const SAFE_MARGIN: u32 = 2_048u32
The amount of bytes one can store safely in a buffer,
without exceeding u32
range. This can be useful if one
wants to store some additional data in a buffer whose
length is represented by Length
.
Sourcepub const MAX_LENGTH: Self
pub const MAX_LENGTH: Self
The maximal value Length
can take. Basically this is
i32::MAX - Self::SAFE_MARGIN
.
Sourcepub const unsafe fn new_unchecked(value: u32) -> Self
pub const unsafe fn new_unchecked(value: u32) -> Self
Creates a new Length
out of u32
.
§Safety
This function does not validate value
. It is up to the
caller to ensure that its value is below or equal to
Length::MAX_LENGTH
.
Sourcepub const fn try_from_u32(value: u32) -> Result<Self, LengthError>
pub const fn try_from_u32(value: u32) -> Result<Self, LengthError>
Sourcepub const fn try_from_i32(value: i32) -> Result<Self, LengthError>
pub const fn try_from_i32(value: i32) -> Result<Self, LengthError>
Trait Implementations§
Source§impl<T: AsI32> AddAssign<T> for Length
impl<T: AsI32> AddAssign<T> for Length
Source§fn add_assign(&mut self, rhs: T)
fn add_assign(&mut self, rhs: T)
Performs the
+=
operation. Read moreSource§impl Ord for Length
impl Ord for Length
Source§impl PartialOrd for Length
impl PartialOrd for Length
Source§impl<T: AsI32> SubAssign<T> for Length
impl<T: AsI32> SubAssign<T> for Length
Source§fn sub_assign(&mut self, rhs: T)
fn sub_assign(&mut self, rhs: T)
Performs the
-=
operation. Read moreimpl Copy for Length
impl Eq for Length
impl StructuralPartialEq for Length
Auto Trait Implementations§
impl Freeze for Length
impl RefUnwindSafe for Length
impl Send for Length
impl Sync for Length
impl Unpin for Length
impl UnwindSafe for Length
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