pub struct VarU16 { /* private fields */ }
Expand description
A variable-width encoded u16
.
VarU16
encodes a 16-bit unsigned integer in a compact form, where the
number of bytes required depends on the value being stored. Small values
fit into a single byte, while larger values require two bytes.
This encoding scheme reserves the most significant bit of the first byte as a flag, indicating the size of the type:
- If
MSB
is0
, the value fits in one byte. - If
MSB
is1
, the value is stored across two bytes.
§Invariants
- Encoded values fit into 15 bits (
value <= u16::MAX >> 1
).
Implementations§
Source§impl VarU16
impl VarU16
Sourcepub const fn try_new(value: u16) -> Result<Self, VarU16SizeError>
pub const fn try_new(value: u16) -> Result<Self, VarU16SizeError>
Tries to create a new VarU16
.
§Errors
Returns a VarU16SizeError
if the given value exceeds the
maximum encodable range (value > u16::MAX >> 1
).
Sourcepub fn into_inner(self) -> u16
pub fn into_inner(self) -> u16
Returns the inner raw u16
value.
Sourcepub fn check_wide(first: u8) -> bool
pub fn check_wide(first: u8) -> bool
Checks whether the given first byte indicates a wide (two-byte) value.
Trait Implementations§
Source§impl Ord for VarU16
impl Ord for VarU16
Source§impl PartialOrd for VarU16
impl PartialOrd for VarU16
impl Copy for VarU16
impl Eq for VarU16
impl StructuralPartialEq for VarU16
Auto Trait Implementations§
impl Freeze for VarU16
impl RefUnwindSafe for VarU16
impl Send for VarU16
impl Sync for VarU16
impl Unpin for VarU16
impl UnwindSafe for VarU16
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