Skip to main content

Word6

Struct Word6 

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

A balanced ternary word consisting of 6 trits.

§Value Range

A Word6 can represent values from -364 to +364:

Value = t0*1 + t1*3 + t2*9 + t3*27 + t4*81 + t5*243
Min: -1 - 3 - 9 - 27 - 81 - 243 = -364
Max: +1 + 3 + 9 + 27 + 81 + 243 = +364

§Internal Representation

Stored as a u16 with 2 bits per trit:

  • Bits 0-1: trit 0 (least significant)
  • Bits 2-3: trit 1
  • Bits 10-11: trit 5 (most significant)

§Examples

use trit_vsa::Word6;

let w = Word6::from_value(100).unwrap();
assert_eq!(w.value(), 100);

let w_neg = -w;
assert_eq!(w_neg.value(), -100);

Implementations§

Source§

impl Word6

Source

pub fn from_value(value: i32) -> Result<Word6, TernaryError>

Create a word from an integer value.

§Arguments
  • value - Integer value (-364 to +364)
§Errors

Returns TernaryError::InvalidWordValue if value is outside range.

§Examples
use trit_vsa::Word6;

let w = Word6::from_value(123).unwrap();
assert_eq!(w.value(), 123);

assert!(Word6::from_value(365).is_err());
assert!(Word6::from_value(-365).is_err());
Source

pub fn from_trits(trits: [Trit; 6]) -> Word6

Create a word from six trits.

§Arguments
  • trits - Array of 6 trits [t0, t1, t2, t3, t4, t5] where t0 is least significant
Source

pub fn from_trytes(low: Tryte3, high: Tryte3) -> Word6

Create a word from two trytes.

§Arguments
  • low - Low tryte (trits 0-2)
  • high - High tryte (trits 3-5)
Source

pub fn value(self) -> i32

Get the integer value of the word.

Source

pub fn to_trits(self) -> [Trit; 6]

Extract the six trits.

§Returns

Array [t0, …, t5] where t0 is least significant.

Source

pub fn to_trytes(self) -> (Tryte3, Tryte3)

Split into two trytes.

§Returns

Tuple (low, high) where low contains trits 0-2 and high contains trits 3-5.

Source

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

Get a specific trit by index.

§Arguments
  • index - Trit index (0-5)
§Panics

Panics if index >= 6.

Source

pub const fn zero() -> Word6

Create a zero word.

Source

pub fn is_zero(self) -> bool

Check if the word is zero.

Source

pub const fn raw(self) -> u16

Get the raw packed representation.

Trait Implementations§

Source§

impl Add for Word6

Source§

fn add(self, other: Word6) -> <Word6 as Add>::Output

Add two words, returning (result, carry).

Source§

type Output = (Word6, Trit)

The resulting type after applying the + operator.
Source§

impl Clone for Word6

Source§

fn clone(&self) -> Word6

Returns a duplicate 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 Word6

Source§

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

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

impl Default for Word6

Source§

fn default() -> Word6

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Word6

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Word6, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Word6

Source§

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

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

impl Hash for Word6

Source§

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

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 for Word6

Source§

fn mul(self, other: Word6) -> <Word6 as Mul>::Output

Multiply two words, returning (low, high) result.

The full result is low + high * 729.

Source§

type Output = (Word6, Word6)

The resulting type after applying the * operator.
Source§

impl Neg for Word6

Source§

type Output = Word6

The resulting type after applying the - operator.
Source§

fn neg(self) -> <Word6 as Neg>::Output

Performs the unary - operation. Read more
Source§

impl PartialEq for Word6

Source§

fn eq(&self, other: &Word6) -> 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 Serialize for Word6

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl TryFrom<i32> for Word6

Source§

type Error = TernaryError

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

fn try_from(value: i32) -> Result<Word6, TernaryError>

Performs the conversion.
Source§

impl Copy for Word6

Source§

impl Eq for Word6

Source§

impl StructuralPartialEq for Word6

Auto Trait Implementations§

§

impl Freeze for Word6

§

impl RefUnwindSafe for Word6

§

impl Send for Word6

§

impl Sync for Word6

§

impl Unpin for Word6

§

impl UnwindSafe for Word6

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> Boilerplate for T
where T: Copy + Send + Sync + Debug + PartialEq + 'static,

Source§

impl<T> CacheKey for T

Source§

impl<T> CacheValue for T

Source§

impl<T> CubeComptime for T
where T: Debug + Hash + Eq + Clone + Copy,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,