pub struct Tryte { /* private fields */ }Expand description
A struct representing a balanced ternary number with a fixed length of 6 digits.
The underlying representation of the number is an array of six Digit values.
This struct provides conversion methods to and from other formats.
Implementations§
Source§impl Tryte
impl Tryte
Sourcepub const fn new(raw: [Digit; 6]) -> Self
pub const fn new(raw: [Digit; 6]) -> Self
Creates a new Tryte instance from a given array of Digits.
§Arguments
raw- An array of exactly 6Digitvalues representing the balanced ternary digits.
§Returns
A new Tryte instance with the specified balanced ternary digits.
§Examples
use balanced_ternary::{Tryte, Digit::{Pos, Zero, Neg}};
let digits = [Pos, Zero, Neg, Zero, Pos, Neg];
let tryte = Tryte::new(digits);
assert_eq!(tryte.to_digit_slice(), &digits);Sourcepub fn to_ternary(&self) -> Ternary
pub fn to_ternary(&self) -> Ternary
Converts the Tryte into its Ternary representation.
§Returns
A Ternary object representing the same balanced ternary number.
Sourcepub const fn to_digit_slice(&self) -> &[Digit]
pub const fn to_digit_slice(&self) -> &[Digit]
Retrieves a slice containing the digits of the Tryte.
§Returns
A slice referencing the six-digit array of the Tryte.
This function allows access to the raw representation of the
balanced ternary number as a slice of Digit values.
Sourcepub fn from_ternary(v: &Ternary) -> Self
pub fn from_ternary(v: &Ternary) -> Self
Sourcepub fn to_i16(&self) -> i16
pub fn to_i16(&self) -> i16
Converts the Tryte into a signed 16-bit integer.
§Returns
A i16 representing the decimal value of the Tryte.