Struct Tryte

Source
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

Source

pub const MAX: Self

364 or ++++++

Source

pub const MIN: Self

-364 or ------

Source

pub const ZERO: Self

0 or 000000

Source

pub fn to_ternary(&self) -> Ternary

Converts the Tryte into its Ternary representation.

§Returns

A Ternary object representing the same balanced ternary number.

Source

pub 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.

Source

pub fn from_ternary(v: &Ternary) -> Self

Creates a Tryte from the given Ternary.

§Arguments
  • v - A reference to a Ternary object.
§Panics

This function panics if the Ternary contains more than 6 digits.

Source

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.

Source

pub fn from_i8(v: i8) -> Self

Creates a Tryte from a signed 8-bit integer.

§Arguments
  • v - An unsigned 8-bit integer.
§Returns

A Tryte representing the equivalent ternary number.

Source

pub fn from_i16(v: i16) -> Self

Creates a Tryte from a signed 16-bit integer.

§Arguments
  • v - A signed 16-bit integer.
§Returns

A Tryte representing the equivalent ternary number.

Source

pub fn digit(&self, index: usize) -> Digit

Retrieves the digit at the specified index in the Tryte.

§Arguments
  • index - The index of the digit to retrieve (0-based, right-to-left).
§Returns

The Digit at the specified index.

§Panics

This function panics if the index is greater than 5.

Trait Implementations§

Source§

impl Add for Tryte

Source§

type Output = Tryte

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl BitAnd for Tryte

Source§

type Output = Tryte

The resulting type after applying the & operator.
Source§

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

Performs the & operation. Read more
Source§

impl BitOr for Tryte

Source§

type Output = Tryte

The resulting type after applying the | operator.
Source§

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

Performs the | operation. Read more
Source§

impl BitXor for Tryte

Source§

type Output = Tryte

The resulting type after applying the ^ operator.
Source§

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

Performs the ^ operation. Read more
Source§

impl Clone for Tryte

Source§

fn clone(&self) -> Tryte

Returns a copy 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 Tryte

Source§

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

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

impl Display for Tryte

Source§

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

Formats the Tryte for display.

The Tryte is displayed in its balanced ternary representation as a 6-character string.

Source§

impl Div for Tryte

Source§

type Output = Tryte

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl From<&str> for Tryte

Source§

fn from(value: &str) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Tryte

Source§

fn from(value: String) -> Self

Converts to this type from the input type.
Source§

impl From<Ternary> for Tryte

Source§

fn from(value: Ternary) -> Self

Converts to this type from the input type.
Source§

impl From<Tryte> for String

Source§

fn from(value: Tryte) -> Self

Converts to this type from the input type.
Source§

impl From<Tryte> for Ternary

Source§

fn from(value: Tryte) -> Self

Converts to this type from the input type.
Source§

impl From<Tryte> for i16

Source§

fn from(value: Tryte) -> Self

Converts to this type from the input type.
Source§

impl From<i16> for Tryte

Source§

fn from(value: i16) -> Self

Converts to this type from the input type.
Source§

impl Hash for Tryte

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

Source§

type Output = Tryte

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Neg for Tryte

Source§

type Output = Tryte

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl Not for Tryte

Source§

type Output = Tryte

The resulting type after applying the ! operator.
Source§

fn not(self) -> Self::Output

Performs the unary ! operation. Read more
Source§

impl PartialEq for Tryte

Source§

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

Source§

type Output = Tryte

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl Copy for Tryte

Source§

impl Eq for Tryte

Source§

impl StructuralPartialEq for Tryte

Auto Trait Implementations§

§

impl Freeze for Tryte

§

impl RefUnwindSafe for Tryte

§

impl Send for Tryte

§

impl Sync for Tryte

§

impl Unpin for Tryte

§

impl UnwindSafe for Tryte

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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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.