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 = 2048
pub const SAFE_MARGIN: u32 = 2048
The amount of bytes one can store safely in a buffer,
without exceeding u32 range. In other words Length::MAX_LENGTH plus
Length::SAFE_MARGIN is guaranteed to never exceed u32::MAX.
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_usize(value: usize) -> Result<Self, LengthError>
pub const fn try_from_usize(value: usize) -> 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)
+= 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)
-= operation. Read more