Hash

Struct Hash 

Source
pub struct Hash(/* private fields */);
👎Deprecated: bee-crypto will not be supported in future versions. You can use functions from iota-crypto instead.
Expand description

Ternary cryptographic hash.

Implementations§

Source§

impl Hash

Source

pub fn zeros() -> Self

👎Deprecated: bee-crypto will not be supported in future versions. You can use functions from iota-crypto instead.

Creates a hash filled with zeros.

Source

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

👎Deprecated: bee-crypto will not be supported in future versions. You can use functions from iota-crypto instead.

Interpret the Hash as a trit slice.

Source

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

👎Deprecated: bee-crypto will not be supported in future versions. You can use functions from iota-crypto instead.

Interpret the Hash as a mutable trit slice.

Source

pub fn weight(&self) -> u8

👎Deprecated: bee-crypto will not be supported in future versions. You can use functions from iota-crypto instead.

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

Methods from Deref<Target = Trits<T1B1>>§

Source

pub fn is_empty(&self) -> bool

Returns true if the trit slice is empty.

Source

pub fn len(&self) -> usize

Returns the number of trits in this trit slice.

Source

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

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

§Panics

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

Source

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

Interpret this slice as a mutable (core::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.

Source

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

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.

Source

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

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.

Source

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

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

Source

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

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.

Source

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

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.

Source

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

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.

Source

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

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.

Source

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

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.

Source

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

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

Source

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

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.

Source

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

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.

Source

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

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

Source

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

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.

Source

pub fn negate(&mut self)

Negate each trit in this buffer.

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

Source

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

View this trit slice as an ordinary slice of trits.

Source

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

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

Source

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

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.

Source

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

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.

Trait Implementations§

Source§

impl Clone for Hash

Source§

fn clone(&self) -> Hash

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 Hash

Source§

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

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

impl DerefMut for Hash

Source§

fn deref_mut(&mut self) -> &mut Trits<T1B1>

Mutably dereferences the value.
Source§

impl Display for Hash

Source§

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

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

impl Hash for Hash

Source§

fn hash<H: Hasher>(&self, hasher: &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 PartialEq for Hash

Source§

fn eq(&self, other: &Self) -> 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<'a, T: RawEncoding<Trit = Btrit>> TryFrom<&'a Trits<T>> for Hash

Source§

type Error = Error

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

fn try_from(trits: &'a Trits<T>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Deref for Hash

Source§

type Target = Trits

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Trits<T1B1>

Dereferences the value.
Source§

impl Copy for Hash

Source§

impl Eq for Hash

Auto Trait Implementations§

§

impl Freeze for Hash

§

impl RefUnwindSafe for Hash

§

impl Send for Hash

§

impl Sync for Hash

§

impl Unpin for Hash

§

impl UnwindSafe for Hash

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<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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.