pub struct Hash(/* private fields */);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
impl Hash
Sourcepub fn zeros() -> Self
👎Deprecated: bee-crypto will not be supported in future versions. You can use functions from iota-crypto instead.
pub fn zeros() -> Self
bee-crypto will not be supported in future versions. You can use functions from iota-crypto instead.Creates a hash filled with zeros.
Sourcepub fn as_trits(&self) -> &Trits<T1B1>
👎Deprecated: bee-crypto will not be supported in future versions. You can use functions from iota-crypto instead.
pub fn as_trits(&self) -> &Trits<T1B1>
bee-crypto will not be supported in future versions. You can use functions from iota-crypto instead.Interpret the Hash as a trit slice.
Sourcepub 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.
pub fn as_trits_mut(&mut self) -> &mut Trits<T1B1>
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.
Methods from Deref<Target = Trits<T1B1>>§
Sourcepub fn as_i8_slice(&self) -> &[i8]
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.
Sourcepub unsafe fn as_i8_slice_mut(&mut self) -> &mut [i8]
pub unsafe fn as_i8_slice_mut(&mut self) -> &mut [i8]
Sourcepub unsafe fn get_unchecked(&self, index: usize) -> <T as RawEncoding>::Trit
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.
Sourcepub unsafe fn set_unchecked(
&mut self,
index: usize,
trit: <T as RawEncoding>::Trit,
)
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.
Sourcepub fn get(&self, index: usize) -> Option<<T as RawEncoding>::Trit>
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.
Sourcepub fn set(&mut self, index: usize, trit: <T as RawEncoding>::Trit)
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.
Sourcepub fn iter(&self) -> impl DoubleEndedIterator + ExactSizeIterator
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.
Sourcepub fn subslice(&self, range: Range<usize>) -> &Trits<T>
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.
Sourcepub fn subslice_mut(&mut self, range: Range<usize>) -> &mut Trits<T>
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.
Sourcepub fn copy_from<U>(&mut self, trits: &Trits<U>)
pub fn copy_from<U>(&mut self, trits: &Trits<U>)
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.
Sourcepub fn fill(&mut self, trit: <T as RawEncoding>::Trit)
pub fn fill(&mut self, trit: <T as RawEncoding>::Trit)
Fill this mutable trit slice with copied of the given trit.
Sourcepub fn to_buf<U>(&self) -> TritBuf<U>where
U: RawEncodingBuf<Slice = T>,
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.
Sourcepub fn chunks(
&self,
chunk_len: usize,
) -> impl DoubleEndedIterator + ExactSizeIterator
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.
Sourcepub fn encode<U>(&self) -> TritBuf<U>where
U: RawEncodingBuf,
<U as RawEncodingBuf>::Slice: RawEncoding<Trit = <T as RawEncoding>::Trit>,
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.
Sourcepub fn iter_trytes(&self) -> impl DoubleEndedIterator + ExactSizeIterator
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.
Sourcepub fn negate(&mut self)
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.
Sourcepub fn as_raw_slice(&self) -> &[T]
pub fn as_raw_slice(&self) -> &[T]
View this trit slice as an ordinary slice of trits.
Sourcepub fn as_raw_slice_mut(&mut self) -> &mut [T]
pub fn as_raw_slice_mut(&mut self) -> &mut [T]
View this mutable trit slice as an ordinary slice of mutable trits.
Sourcepub fn chunks_mut(
&mut self,
chunk_len: usize,
) -> impl Iterator<Item = &mut Trits<T1B1<T>>>
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.
Sourcepub fn iter_mut(&mut self) -> IterMut<'_, T>
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.