pub struct LinkedByte(/* private fields */);
Expand description
An element in a series of Linked Bytes.
Implementations§
Source§impl LinkedByte
impl LinkedByte
Sourcepub const VALUE_MASK: u8 = 127u8
pub const VALUE_MASK: u8 = 127u8
The value bit mask.
Use value
to easily check for this.
Sourcepub const ZERO_LINK: Self
pub const ZERO_LINK: Self
The zero value as a linked byte (one or more follow-up bytes expected).
Sourcepub const MAX: u8 = 127u8
pub const MAX: u8 = 127u8
The largest value representable, as a u8
.
The value is 127
, since the individual Linked Bytes are 7-bit, plus the link/end flag.
Sourcepub const fn is_linked(self) -> bool
pub const fn is_linked(self) -> bool
Returns true
if the byte is linked to a following byte, false
otherwise.
The opposite of is_end
.
Sourcepub const fn is_end(self) -> bool
pub const fn is_end(self) -> bool
Returns true
if the byte is not linked to a following byte (i.e. is an endpoint), false
otherwise.
The opposite of is_linked
.
Sourcepub const fn value(self) -> u8
pub const fn value(self) -> u8
Returns the value of the linked byte, in the range from 0 to 127, inclusively.
The main use for this is performing arithmetic with linked bytes.
Sourcepub const fn into_linked(self) -> Self
pub const fn into_linked(self) -> Self
Sets the link bit to true
(linked state).
Sourcepub fn make_linked(&mut self)
pub fn make_linked(&mut self)
Converts self
into the linked state in place.
Sourcepub fn checked_add(self, rhs: Self) -> Option<Self>
pub fn checked_add(self, rhs: Self) -> Option<Self>
Performs checked addition. None
is returned if the result overflows the limit of 127.
Sourcepub fn add_with_carry(self, rhs: Self) -> (Self, bool)
pub fn add_with_carry(self, rhs: Self) -> (Self, bool)
Performs checked wrapping addition. Unlike checked_add
, this method returns a tuple, in which the first value is the result, which wraps over if the result overflows the limit of 127, and the second value is whether the overflow actually occurred.
Sourcepub fn checked_sub(self, rhs: Self) -> Option<Self>
pub fn checked_sub(self, rhs: Self) -> Option<Self>
Performs checked subtraction. None
is returned if the result underflows the limit of 0.
Sourcepub fn sub_with_borrow(self, rhs: Self) -> (Self, bool)
pub fn sub_with_borrow(self, rhs: Self) -> (Self, bool)
Performs checked wrapping subtraction. Unlike checked_sub
, this method returns a tuple, in which the first value is the result, which wraps over if the result underflows the limit of 0, and the second value is whether the overflow actually occurred.
Sourcepub const fn into_inner(self) -> u8
pub const fn into_inner(self) -> u8
Consumes the value and unwraps it into its inner u8
, retaining the link bit if it’s set.
Use into_int7
if you need only the value without the link bit, which is usually the case.
Sourcepub const fn into_int7(self) -> u8
pub const fn into_int7(self) -> u8
Consumes the value and unwraps it into its inner 7-bit integer, i.e. dropping the link bit if it’s set.
Use into_inner
if you need the unmodified value with the link bit unmodified.
Trait Implementations§
Source§impl Clone for LinkedByte
impl Clone for LinkedByte
Source§fn clone(&self) -> LinkedByte
fn clone(&self) -> LinkedByte
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for LinkedByte
impl Debug for LinkedByte
Source§impl From<LinkedByte> for u8
impl From<LinkedByte> for u8
Source§fn from(op: LinkedByte) -> Self
fn from(op: LinkedByte) -> Self
Consumes the byte and unwraps it into its inner u8
, retaining the link bit if it’s set.
Source§impl From<u8> for LinkedByte
impl From<u8> for LinkedByte
Source§impl FromIterator<LinkedByte> for LBNum
impl FromIterator<LinkedByte> for LBNum
Source§fn from_iter<T: IntoIterator<Item = LinkedByte>>(op: T) -> Self
fn from_iter<T: IntoIterator<Item = LinkedByte>>(op: T) -> Self
Converts an iterator over linked bytes into an LBNum. Little-endian byte order is assumed, regardless of platform.
If any of the bytes except for the last one are endpoints (most significant bit cleared), they are converted into linked (most significant bit set), and if the last byte is linked, it’s converted into and endpoint.
If possible, use TryFrom
or from_sequence
instead.
Source§impl FromIterator<LinkedByte> for LBSequence
impl FromIterator<LinkedByte> for LBSequence
Source§fn from_iter<T: IntoIterator<Item = LinkedByte>>(op: T) -> Self
fn from_iter<T: IntoIterator<Item = LinkedByte>>(op: T) -> Self
Converts an iterator over linked bytes into an LBSequence
. Little-endian byte order is assumed, regardless of platform.