Struct crypto::hashes::ternary::Hash[][src]

pub struct Hash(_);
This is supported on crate feature ternary_hashes only.

Ternary cryptographic hash.

Implementations

impl Hash[src]

pub fn zeros() -> Self[src]

Creates a hash filled with zeros.

pub fn as_trits(&self) -> &Trits<T1B1>[src]

Interpret the Hash as a trit slice.

pub fn as_trits_mut(&mut self) -> &mut Trits<T1B1>[src]

Interpret the Hash as a mutable trit slice.

pub fn weight(&self) -> u8[src]

Returns the weight - number of ending 0s - of the Hash.

Methods from Deref<Target = Trits<T1B1>>

pub fn is_empty(&self) -> bool[src]

Returns true if the trit slice is empty.

pub fn len(&self) -> usize[src]

Returns the number of trits in this trit slice.

pub fn as_i8_slice(&self) -> &[i8][src]

Interpret this slice as an (std::i8) slice.

Panics

This function will panic if the slice is not byte-aligned.

pub unsafe fn as_i8_slice_mut(&mut self) -> &mut [i8][src]

Interpret this slice as a mutable (std::i8) slice.

Panics

This function will panic if the slice is not byte-aligned.

Safety

This function is marked unsafe because modification of the trit slice in a manner that is not valid for this encoding is undefined behaviour.

pub unsafe fn get_unchecked(&self, index: usize) -> <T as RawEncoding>::Trit[src]

Fetch the trit at the given index of this trit slice without first checking whether the index is in bounds. Providing an index that is not less than the length of this slice is undefined behaviour.

This is perhaps the ‘least bad’ unsafe function in this crate: not because any form of undefined behaviour is better or worse than another (after all, the point of undefined behaviour is that it is undefined) but because it’s the easiest to use correctly.

Safety

An index with a value less then the result of Trits::len must be used. Any other value is undefined behaviour.

pub unsafe fn set_unchecked(
    &mut self,
    index: usize,
    trit: <T as RawEncoding>::Trit
)
[src]

Set the trit at the given index of this trit slice without first checking whether the index is in bounds. Providing an index that is not less than the length of this slice is undefined behaviour.

This is perhaps the ‘least bad’ unsafe function in this crate: not because any form of undefined behaviour is better or worse than another (after all, the point of undefined behaviour is that it is undefined) but because it’s the easiest to use correctly.

Safety

An index with a value less then the result of Trits::len must be used. Any other value is undefined behaviour.

pub fn get(&self, index: usize) -> Option<<T as RawEncoding>::Trit>[src]

Fetch the trit at the given index of this trit slice, if the index is valid.

pub fn set(&mut self, index: usize, trit: <T as RawEncoding>::Trit)[src]

Set the trit at the given index of this mutable trit slice, if the index is valid.

Panics

This function will panic if the index is not less than the length of this slice.

pub fn iter(&self) -> impl DoubleEndedIterator + ExactSizeIterator[src]

Returns an iterator over the trits in this slice.

Using this function is significantly faster than calling Trits::get in a loop and should be used where possible.

pub fn subslice(&self, range: Range<usize>) -> &Trits<T>[src]

Returns a subslice of this slice with the given range of trits.

Panics

This function will panic if called with a range that contains indices outside this slice, or the start of the range is greater than its end.

pub fn subslice_mut(&mut self, range: Range<usize>) -> &mut Trits<T>[src]

Returns a mutable subslice of this mutable slice with the given range of trits.

Panics

This function will panic if called with a range that contains indices outside this slice, or the start of the range is greater than its end.

pub fn copy_from<U>(&mut self, trits: &Trits<U>) where
    U: RawEncoding<Trit = <T as RawEncoding>::Trit> + ?Sized
[src]

Copy the trits from a trit slice into this mutable trit slice (the encoding need not be equivalent).

Panics

This function will panic if the length of the slices are different.

pub fn fill(&mut self, trit: <T as RawEncoding>::Trit)[src]

Fill this mutable trit slice with copied of the given trit.

pub fn to_buf<U>(&self) -> TritBuf<U> where
    U: RawEncodingBuf<Slice = T>, 
[src]

Copy the contents of this trit slice into a new TritBuf with the same encoding. This function is analogous to to_vec method implemented on ordinary slices.

pub fn chunks(
    &self,
    chunk_len: usize
) -> impl DoubleEndedIterator + ExactSizeIterator
[src]

Return an iterator over distinct, non-overlapping subslices of this trit slice, each with the given chunk length. If the length of the trit slice is not a multiple of the given chunk length, the last slice provided by the iterator will be smaller to compensate.

Panics

This function will panic if the given chunk length is 0.

pub fn encode<U>(&self) -> TritBuf<U> where
    U: RawEncodingBuf,
    <U as RawEncodingBuf>::Slice: RawEncoding,
    <<U as RawEncodingBuf>::Slice as RawEncoding>::Trit == <T as RawEncoding>::Trit
[src]

Encode the contents of this trit slice into a TritBuf with a different encoding.

pub fn iter_trytes(&self) -> impl DoubleEndedIterator + ExactSizeIterator[src]

Returns an iterator over the trytes represented within this slice.

For encodings that are representation-compatible with trytes, such as T3B1, use Trits::as_trytes instead since it is faster and more capable.

pub fn negate(&mut self)[src]

Negate each trit in this buffer.

This has the effect of making the trit buffer negative when expressed in numeric form.

pub fn as_raw_slice(&self) -> &[T][src]

View this trit slice as an ordinary slice of trits.

pub fn as_raw_slice_mut(&mut self) -> &mut [T][src]

View this mutable trit slice as an ordinary slice of mutable trits.

pub fn chunks_mut(
    &mut self,
    chunk_len: usize
) -> impl Iterator<Item = &mut Trits<T1B1<T>>>
[src]

Return an iterator over distinct, non-overlapping mutable subslices of this mutable trit slice, each with the given chunk length. If the length of the trit slice is not a multiple of the given chunk length, the last slice provided by the iterator will be smaller to compensate.

Panics

This function will panic if the given chunk length is 0.

pub fn iter_mut(&mut self) -> IterMut<'_, T>[src]

Returns a mutable iterator over the trits in this slice.

Using this function is significantly faster than calling Trits::set in a loop and should be used where possible.

pub fn as_trytes(&self) -> &[Tryte][src]

Interpret this trit slice as a Tryte slice.

Panics

This function will panic if the length of the slice is not a multiple of 3, or if the slice is not byte-aligned.

pub fn as_trytes_mut(&mut self) -> &mut [Tryte][src]

Interpret this mutable trit slice as a mutable Tryte slice.

Panics

This function will panic if the length of the slice is not a multiple of 3, or if the slice is not byte-aligned.

Trait Implementations

impl Clone for Hash[src]

impl Copy for Hash[src]

impl Debug for Hash[src]

impl Deref for Hash[src]

type Target = Trits<T1B1>

The resulting type after dereferencing.

impl DerefMut for Hash[src]

impl Display for Hash[src]

impl Eq for Hash[src]

impl Hash for Hash[src]

impl PartialEq<Hash> for Hash[src]

impl<'a, T: RawEncoding<Trit = Btrit>> TryFrom<&'a Trits<T>> for Hash[src]

type Error = HashError

The type returned in the event of a conversion error.

Auto Trait Implementations

impl RefUnwindSafe for Hash

impl Send for Hash

impl Sync for Hash

impl Unpin for Hash

impl UnwindSafe for Hash

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.