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
impl Word6
Sourcepub fn from_value(value: i32) -> Result<Word6, TernaryError>
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());Sourcepub fn from_trits(trits: [Trit; 6]) -> Word6
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
Sourcepub fn from_trytes(low: Tryte3, high: Tryte3) -> Word6
pub fn from_trytes(low: Tryte3, high: Tryte3) -> Word6
Sourcepub fn to_trytes(self) -> (Tryte3, Tryte3)
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.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Word6
impl<'de> Deserialize<'de> for Word6
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Word6, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
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 Serialize for Word6
impl Serialize for Word6
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
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
impl Copy for Word6
impl Eq for Word6
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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