Struct LinkedByte

Source
pub struct LinkedByte(/* private fields */);
Expand description

An element in a series of Linked Bytes.

Implementations§

Source§

impl LinkedByte

The link bit mask.

Use is_linked to easily check for this.

Source

pub const VALUE_MASK: u8 = 127u8

The value bit mask.

Use value to easily check for this.

Source

pub const ZERO_END: Self

The zero value as an endpoint (no follow-up bytes expected).

The zero value as a linked byte (one or more follow-up bytes expected).

Source

pub const MIN: u8 = 0u8

The smallest value representable, as a u8.

Alias for ZERO_END.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub const fn into_linked(self) -> Self

Sets the link bit to true (linked state).

Source

pub fn make_linked(&mut self)

Converts self into the linked state in place.

Source

pub const fn into_end(self) -> Self

Sets the link bit to false (endpoint state).

Source

pub fn make_end(&mut self)

Converts self into the linked state in place.

Source

pub fn checked_add(self, rhs: Self) -> Option<Self>

Performs checked addition. None is returned if the result overflows the limit of 127.

Source

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.

Source

pub fn checked_sub(self, rhs: Self) -> Option<Self>

Performs checked subtraction. None is returned if the result underflows the limit of 0.

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> LinkedByte

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LinkedByte

Source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl From<(u8, bool)> for LinkedByte

Source§

fn from(op: (u8, bool)) -> Self

Constructs either a linked or an endpoint byte depending on the second argument.

The most significant bit is silently dropped.

Source§

impl From<LinkedByte> for u8

Source§

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

Source§

fn from(op: u8) -> Self

Constructs an endpoint byte from a u8.

The most significant bit is silently dropped. Use into_linked to convert the result into a linked byte if you actually want to initialize it like that.

Source§

impl FromIterator<LinkedByte> for LBNum

Source§

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

Source§

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.

Source§

impl Ord for LinkedByte

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for LinkedByte

Source§

fn eq(&self, other: &LinkedByte) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for LinkedByte

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for LinkedByte

Source§

impl Eq for LinkedByte

Source§

impl StructuralPartialEq for LinkedByte

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.