[][src]Struct bigbit::headbyte::Exponent

pub struct Exponent(_);

An exponent for the Head Byte format.

To retreive the real value of a Head Byte number, its stored value is multiplied by 10 raised to the power of this value as retreived using into_inner.

This is not a 2's complement signed number: it ranges from -127 to +127, having one bit as the sign and the rest as a normal 7-bit unsigned integer. As a consequence, it's possible to store 0b1_0000000 as the exponent, meaning a resulting exponent of 10⁻⁰, i.e. 10 ÷ 0, which results in infinity. In most cases, this transformation is unwanted (that is, accidential, most likely happening because of a serious mistake during bitwise operations), and as such is not allowed, producing a TryFrom error.

In other words, protection against -0 is a safety guarantee, and actually creating an exponent with this value requires unsafe code.

Methods

impl Exponent[src]

#[must_use]pub unsafe fn from_u8_unchecked(op: u8) -> Self[src]

Wraps a byte into an exponent, ignoring the invalid 0b1_0000000 case.

This is the unsafe unchecked version of the TryFrom implementation.

Safety

The value must never be 0b1_0000000 (-0), since avoiding that case is a safety guaranteee of the Exponent type.

#[must_use]pub fn into_inner(self) -> u8[src]

Consumes the value and returns the inner byte.

See the struct-level documentation for the meaning of this value.

Trait Implementations

impl Clone for Exponent[src]

impl Copy for Exponent[src]

impl Debug for Exponent[src]

impl Eq for Exponent[src]

impl From<Exponent> for u8[src]

#[must_use]fn from(op: Exponent) -> Self[src]

Consumes the exponent and returns the underlying inner byte.

impl PartialEq<Exponent> for Exponent[src]

impl StructuralEq for Exponent[src]

impl StructuralPartialEq for Exponent[src]

impl TryFrom<u8> for Exponent[src]

type Error = InvalidExponentError

The type returned in the event of a conversion error.

fn try_from(op: u8) -> Result<Self, InvalidExponentError>[src]

Wraps a byte into an exponent.

Errors

If the supplied value is 0b1_0000000 (-0), Err(InvalidExponentError) is returned, where InvalidExponentError is a marker error type.

Auto Trait Implementations

impl Send for Exponent

impl Sync for Exponent

impl Unpin for Exponent

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.