Skip to main content

Word

Struct Word 

Source
pub struct Word<const N: usize>(/* private fields */);
Expand description

A fixed-width balanced ternary integer containing N trits.

Trits are stored in little-endian order: index zero is the least-significant trit.

Implementations§

Source§

impl<const N: usize> Word<N>

Source

pub const TRIT_COUNT: usize = N

Number of trits in this word.

Source

pub const fn new(trits: [Trit; N]) -> Self

Creates a word from little-endian trits.

The first array element is the least-significant trit.

Source

pub const fn zero() -> Self

Creates a word with all trits equal to zero.

Source

pub const fn into_trits(self) -> [Trit; N]

Returns the stored trits in little-endian order.

Source

pub fn get_trit(self, index: usize) -> Option<Trit>

Returns the trit at index, or None if it is out of bounds.

Trit zero is the least-significant trit.

Source

pub const fn trit(self, index: usize) -> Trit

Returns the trit at index.

§Panics

Panics if index >= Self::TRIT_COUNT.

Source

pub fn negate(self) -> Self

Returns the arithmetic negation of this word.

Source

pub fn sign(self) -> Trit

Returns Trit::N, Trit::Z, or Trit::P according to numeric sign.

Source

pub fn abs(self) -> Self

Returns the non-negative magnitude of this word.

Source

pub fn truncate<const W: usize>(self) -> Word<W>

Truncates this word to its least-significant W trits.

§Panics

Panics if W > N. This is a raw fixed-width truncation operation; it does not check whether the value can be represented losslessly.

Source§

impl Word<3>

Source

pub const MIN_INT: i8

The minimum representable value for a tribble.

Source

pub const MAX_INT: i8

The maximum representable value for a tribble.

Source

pub fn to_int(self) -> i8

Converts this tribble to its native integer representation.

Source

pub fn from_int(value: i8) -> Result<Self, WordError>

Constructs a tribble from a native integer.

§Errors

Returns WordError::OutOfRange if value is outside Tribble::MIN_INT through Tribble::MAX_INT.

Source§

impl Word<9>

Source

pub const MIN_INT: i16

The minimum representable value for a tryte.

Source

pub const MAX_INT: i16

The maximum representable value for a tryte.

Source

pub fn to_int(self) -> i16

Converts this tryte to its native integer representation.

Source

pub fn from_int(value: i16) -> Result<Self, WordError>

Constructs a tryte from a native integer.

§Errors

Returns WordError::OutOfRange if value is outside Tryte::MIN_INT through Tryte::MAX_INT.

Source§

impl Word<27>

Source

pub const MIN_INT: i64

The minimum representable value for a 27-trit word.

Source

pub const MAX_INT: i64

The maximum representable value for a 27-trit word.

Source

pub fn to_int(self) -> i64

Converts this 27-trit word to its native integer representation.

Source

pub fn from_int(value: i64) -> Result<Self, WordError>

Constructs a 27-trit word from a native integer.

§Errors

Returns WordError::OutOfRange if value is outside Word27::MIN_INT through Word27::MAX_INT.

Source§

impl Word<54>

Source

pub const MIN_INT: i128

The minimum representable value for a 54-trit word.

Source

pub const MAX_INT: i128

The maximum representable value for a 54-trit word.

Source

pub fn to_int(self) -> i128

Converts this 54-trit word to its native integer representation.

Source

pub fn from_int(value: i128) -> Result<Self, WordError>

Constructs a 54-trit word from a native integer.

§Errors

Returns WordError::OutOfRange if value is outside Word54::MIN_INT through Word54::MAX_INT.

Source§

impl<const N: usize> Word<N>

Source

pub fn tmin(self, rhs: Self) -> Self

Returns the component-wise ternary minimum.

Source

pub fn tmax(self, rhs: Self) -> Self

Returns the component-wise ternary maximum.

Source

pub fn tnot(self) -> Self

Returns the tritwise ternary negation.

Each N becomes P, each P becomes N, and Z remains Z.

Source

pub fn tclip(self) -> Self

Returns the tritwise clipping of this word.

Source

pub fn signum(self) -> Self

Returns a word-valued numeric sign: -1, 0, or +1.

Source

pub fn tconsensus(self, rhs: Self) -> Self

Returns the tritwise consensus of two words.

Source

pub fn tshl(self, count: usize) -> Self

Shifts trits left by count, filling low trits with zero.

If count >= Self::TRIT_COUNT, returns zero.

Source

pub fn tshr(self, count: usize) -> Self

Returns the arithmetic right shift by count trits.

Vacated most-significant trits are filled with the numeric sign. If count >= Self::TRIT_COUNT, every trit becomes the sign trit.

Source

pub fn tlshr(self, count: usize) -> Self

Returns the logical right shift by count trits.

Vacated most-significant trits are filled with zero. If count >= Self::TRIT_COUNT, returns zero.

Trait Implementations§

Source§

impl Add<Word<27>> for Word54

Source§

type Output = Word<54>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Word27) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Word<27>> for Tryte

Source§

type Output = Word<27>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Word27) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Word<54>> for Word27

Source§

type Output = Word<54>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Word54) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Word<54>> for Tryte

Source§

type Output = Word<54>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Word54) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Word<9>> for Word27

Source§

type Output = Word<27>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Tryte) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Word<9>> for Word54

Source§

type Output = Word<54>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Tryte) -> Self::Output

Performs the + operation. Read more
Source§

impl<const N: usize> Add for Word<N>

Source§

type Output = Word<N>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl CheckedDiv<Word<27>> for Word54

Source§

type Output = Word<54>

The type produced by a successful division.
Source§

fn checked_div(self, rhs: Word27) -> Option<Self::Output>

Divides self by rhs, returning None when rhs is zero.
Source§

impl CheckedDiv<Word<27>> for Tryte

Source§

type Output = Word<27>

The type produced by a successful division.
Source§

fn checked_div(self, rhs: Word27) -> Option<Self::Output>

Divides self by rhs, returning None when rhs is zero.
Source§

impl CheckedDiv<Word<54>> for Word27

Source§

type Output = Word<54>

The type produced by a successful division.
Source§

fn checked_div(self, rhs: Word54) -> Option<Self::Output>

Divides self by rhs, returning None when rhs is zero.
Source§

impl CheckedDiv<Word<54>> for Tryte

Source§

type Output = Word<54>

The type produced by a successful division.
Source§

fn checked_div(self, rhs: Word54) -> Option<Self::Output>

Divides self by rhs, returning None when rhs is zero.
Source§

impl CheckedDiv<Word<9>> for Word27

Source§

type Output = Word<27>

The type produced by a successful division.
Source§

fn checked_div(self, rhs: Tryte) -> Option<Self::Output>

Divides self by rhs, returning None when rhs is zero.
Source§

impl CheckedDiv<Word<9>> for Word54

Source§

type Output = Word<54>

The type produced by a successful division.
Source§

fn checked_div(self, rhs: Tryte) -> Option<Self::Output>

Divides self by rhs, returning None when rhs is zero.
Source§

impl<const N: usize> Clone for Word<N>

Source§

fn clone(&self) -> Word<N>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<const N: usize> Debug for Word<N>

Source§

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

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

impl<const N: usize> Display for Word<N>

Source§

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

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

impl Div<Word<27>> for Word54

Source§

type Output = Word<54>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Word27) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<Word<27>> for Tryte

Source§

type Output = Word<27>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Word27) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<Word<54>> for Word27

Source§

type Output = Word<54>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Word54) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<Word<54>> for Tryte

Source§

type Output = Word<54>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Word54) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<Word<9>> for Word27

Source§

type Output = Word<27>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Tryte) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<Word<9>> for Word54

Source§

type Output = Word<54>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Tryte) -> Self::Output

Performs the / operation. Read more
Source§

impl From<Word<27>> for Word54

Source§

fn from(value: Word27) -> Self

Converts to this type from the input type.
Source§

impl From<Word<27>> for i64

Source§

fn from(word: Word27) -> Self

Converts to this type from the input type.
Source§

impl From<Word<3>> for i8

Source§

fn from(word: Tribble) -> Self

Converts to this type from the input type.
Source§

impl From<Word<54>> for i128

Source§

fn from(word: Word54) -> Self

Converts to this type from the input type.
Source§

impl From<Word<9>> for Word27

Source§

fn from(value: Tryte) -> Self

Converts to this type from the input type.
Source§

impl From<Word<9>> for Word54

Source§

fn from(value: Tryte) -> Self

Converts to this type from the input type.
Source§

impl From<Word<9>> for i16

Source§

fn from(word: Tryte) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize> Hash for Word<N>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Mul<Word<27>> for Word54

Source§

type Output = Word<54>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Word27) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Word<27>> for Tryte

Source§

type Output = Word<27>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Word27) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Word<54>> for Word27

Source§

type Output = Word<54>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Word54) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Word<54>> for Tryte

Source§

type Output = Word<54>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Word54) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Word<9>> for Word27

Source§

type Output = Word<27>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Tryte) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Word<9>> for Word54

Source§

type Output = Word<54>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Tryte) -> Self::Output

Performs the * operation. Read more
Source§

impl<const N: usize> Mul for Word<N>

Source§

type Output = Word<N>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl<const N: usize> Neg for Word<N>

Source§

type Output = Word<N>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<const N: usize> Ord for Word<N>

Source§

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

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

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

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

impl<const N: usize> PartialEq for Word<N>

Source§

fn eq(&self, other: &Word<N>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<const N: usize> PartialOrd for Word<N>

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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 Sub<Word<27>> for Word54

Source§

type Output = Word<54>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Word27) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub<Word<27>> for Tryte

Source§

type Output = Word<27>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Word27) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub<Word<54>> for Word27

Source§

type Output = Word<54>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Word54) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub<Word<54>> for Tryte

Source§

type Output = Word<54>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Word54) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub<Word<9>> for Word27

Source§

type Output = Word<27>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Tryte) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub<Word<9>> for Word54

Source§

type Output = Word<54>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Tryte) -> Self::Output

Performs the - operation. Read more
Source§

impl<const N: usize> Sub for Word<N>

Source§

type Output = Word<N>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl<const N: usize> Copy for Word<N>

Source§

impl<const N: usize> Eq for Word<N>

Source§

impl<const N: usize> StructuralPartialEq for Word<N>

Auto Trait Implementations§

§

impl<const N: usize> Freeze for Word<N>

§

impl<const N: usize> RefUnwindSafe for Word<N>

§

impl<const N: usize> Send for Word<N>

§

impl<const N: usize> Sync for Word<N>

§

impl<const N: usize> Unpin for Word<N>

§

impl<const N: usize> UnsafeUnpin for Word<N>

§

impl<const N: usize> UnwindSafe for Word<N>

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.