Struct bee_ternary::TritBuf
source · [−]#[repr(transparent)]pub struct TritBuf<T: RawEncodingBuf = T1B1Buf<Btrit>>(_);
Expand description
Implementations
sourceimpl<T: RawEncodingBuf> TritBuf<T>
impl<T: RawEncodingBuf> TritBuf<T>
sourcepub fn with_capacity(cap: usize) -> Self
pub fn with_capacity(cap: usize) -> Self
sourcepub fn filled(len: usize, trit: <T::Slice as RawEncoding>::Trit) -> Self
pub fn filled(len: usize, trit: <T::Slice as RawEncoding>::Trit) -> Self
Create a new TritBuf
of the given length, filled with copies of the provided trit.
sourcepub fn zeros(len: usize) -> Self
pub fn zeros(len: usize) -> Self
Create a new TritBuf
of the given length, filled with zero trit.
sourcepub fn from_trits(trits: &[<T::Slice as RawEncoding>::Trit]) -> Self
pub fn from_trits(trits: &[<T::Slice as RawEncoding>::Trit]) -> Self
Create a new TritBuf
containing the trits from the given slice of trits.
sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears the buffer, removing all values. Note that this method has no effect on the allocated capacity of the buffer.
sourcepub fn push(&mut self, trit: <T::Slice as RawEncoding>::Trit)
pub fn push(&mut self, trit: <T::Slice as RawEncoding>::Trit)
Push a trit to the back of this TritBuf
.
sourcepub fn pop(&mut self) -> Option<<T::Slice as RawEncoding>::Trit>
pub fn pop(&mut self) -> Option<<T::Slice as RawEncoding>::Trit>
Pop a trit from the back of this TritBuf
, returning it if successful.
sourcepub fn append<U: RawEncoding<Trit = <T::Slice as RawEncoding>::Trit> + ?Sized>(
&mut self,
trits: &Trits<U>
)
pub fn append<U: RawEncoding<Trit = <T::Slice as RawEncoding>::Trit> + ?Sized>(
&mut self,
trits: &Trits<U>
)
Append a trit slice to the end of this TritBuf
.
sourcepub fn as_slice_mut(&mut self) -> &mut Trits<T::Slice>
pub fn as_slice_mut(&mut self) -> &mut Trits<T::Slice>
sourceimpl TritBuf<T3B1Buf>
impl TritBuf<T3B1Buf>
sourcepub fn pad_zeros(&mut self)
pub fn pad_zeros(&mut self)
Pad the trit buffer with Btrit::Zero
until the buffer’s length is a multiple of 3.
This method is often used in conjunction with Trits::as_trytes
.
sourcepub fn padded_zeros(self) -> Self
pub fn padded_zeros(self) -> Self
Pad the trit buffer with Btrit::Zero
until the buffer’s length is a multiple of 3.
This method is often used in conjunction with Trits::as_trytes
.
sourceimpl<T: RawEncodingBuf> TritBuf<T>where
T::Slice: RawEncoding<Trit = Btrit>,
impl<T: RawEncodingBuf> TritBuf<T>where
T::Slice: RawEncoding<Trit = Btrit>,
sourceimpl<T: RawEncodingBuf> TritBuf<T>where
T::Slice: RawEncoding<Trit = Utrit>,
impl<T: RawEncodingBuf> TritBuf<T>where
T::Slice: RawEncoding<Trit = Utrit>,
Methods from Deref<Target = Trits<T::Slice>>
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::Trit
pub unsafe fn get_unchecked(&self, index: usize) -> T::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::Trit)
pub unsafe fn set_unchecked(&mut self, index: usize, trit: T::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::Trit>
pub fn get(&self, index: usize) -> Option<T::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::Trit)
pub fn set(&mut self, index: usize, trit: T::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<Item = T::Trit> + ExactSizeIterator<Item = T::Trit> + '_
pub fn iter(
&self
) -> impl DoubleEndedIterator<Item = T::Trit> + ExactSizeIterator<Item = T::Trit> + '_
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>) -> &Self
pub fn subslice(&self, range: Range<usize>) -> &Self
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 Self
pub fn subslice_mut(&mut self, range: Range<usize>) -> &mut Self
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: RawEncoding<Trit = T::Trit> + ?Sized>(
&mut self,
trits: &Trits<U>
)
pub fn copy_from<U: RawEncoding<Trit = T::Trit> + ?Sized>(
&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::Trit)
pub fn fill(&mut self, trit: T::Trit)
Fill this mutable trit slice with copied of the given trit.
sourcepub fn to_buf<U: RawEncodingBuf<Slice = T>>(&self) -> TritBuf<U>
pub fn to_buf<U: RawEncodingBuf<Slice = T>>(&self) -> TritBuf<U>
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<Item = &Self> + ExactSizeIterator<Item = &Self> + '_
pub fn chunks(
&self,
chunk_len: usize
) -> impl DoubleEndedIterator<Item = &Self> + ExactSizeIterator<Item = &Self> + '_
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::Slice: RawEncoding<Trit = T::Trit>,
pub fn encode<U>(&self) -> TritBuf<U>where
U: RawEncodingBuf,
U::Slice: RawEncoding<Trit = T::Trit>,
Encode the contents of this trit slice into a TritBuf
with a different encoding.
sourcepub fn iter_trytes(
&self
) -> impl DoubleEndedIterator<Item = Tryte> + ExactSizeIterator<Item = Tryte> + '_
pub fn iter_trytes(
&self
) -> impl DoubleEndedIterator<Item = Tryte> + ExactSizeIterator<Item = Tryte> + '_
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 as_raw_slice(&self) -> &[T]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
pub fn as_raw_slice(&self) -> &[T]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
View this trit slice as an ordinary slice of trits.
sourcepub fn as_raw_slice_mut(&mut self) -> &mut [T]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
pub fn as_raw_slice_mut(&mut self) -> &mut [T]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
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 Self> + '_
pub fn chunks_mut(
&mut self,
chunk_len: usize
) -> impl Iterator<Item = &mut Self> + '_
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.
Trait Implementations
sourceimpl<T: RawEncodingBuf> Borrow<Trits<<T as RawEncodingBuf>::Slice>> for TritBuf<T>
impl<T: RawEncodingBuf> Borrow<Trits<<T as RawEncodingBuf>::Slice>> for TritBuf<T>
sourceimpl<T: RawEncodingBuf> BorrowMut<Trits<<T as RawEncodingBuf>::Slice>> for TritBuf<T>
impl<T: RawEncodingBuf> BorrowMut<Trits<<T as RawEncodingBuf>::Slice>> for TritBuf<T>
sourcefn borrow_mut(&mut self) -> &mut Trits<T::Slice>
fn borrow_mut(&mut self) -> &mut Trits<T::Slice>
sourceimpl<T: Clone + RawEncodingBuf> Clone for TritBuf<T>
impl<T: Clone + RawEncodingBuf> Clone for TritBuf<T>
sourceimpl<T: RawEncodingBuf> Debug for TritBuf<T>
impl<T: RawEncodingBuf> Debug for TritBuf<T>
sourceimpl<T: RawEncodingBuf> Default for TritBuf<T>
impl<T: RawEncodingBuf> Default for TritBuf<T>
sourceimpl<T: RawEncodingBuf> Deref for TritBuf<T>
impl<T: RawEncodingBuf> Deref for TritBuf<T>
sourceimpl<T: RawEncodingBuf> DerefMut for TritBuf<T>
impl<T: RawEncodingBuf> DerefMut for TritBuf<T>
sourceimpl<'de, T: RawEncodingBuf> Deserialize<'de> for TritBuf<T>where
<T::Slice as RawEncoding>::Trit: Deserialize<'de>,
impl<'de, T: RawEncodingBuf> Deserialize<'de> for TritBuf<T>where
<T::Slice as RawEncoding>::Trit: Deserialize<'de>,
sourcefn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
sourceimpl<T: RawEncodingBuf> Display for TritBuf<T>
impl<T: RawEncodingBuf> Display for TritBuf<T>
sourceimpl<T: RawEncodingBuf> From<i128> for TritBuf<T>where
T::Slice: RawEncoding<Trit = Btrit>,
impl<T: RawEncodingBuf> From<i128> for TritBuf<T>where
T::Slice: RawEncoding<Trit = Btrit>,
sourceimpl<T: RawEncodingBuf> From<i16> for TritBuf<T>where
T::Slice: RawEncoding<Trit = Btrit>,
impl<T: RawEncodingBuf> From<i16> for TritBuf<T>where
T::Slice: RawEncoding<Trit = Btrit>,
sourceimpl<T: RawEncodingBuf> From<i32> for TritBuf<T>where
T::Slice: RawEncoding<Trit = Btrit>,
impl<T: RawEncodingBuf> From<i32> for TritBuf<T>where
T::Slice: RawEncoding<Trit = Btrit>,
sourceimpl<T: RawEncodingBuf> From<i64> for TritBuf<T>where
T::Slice: RawEncoding<Trit = Btrit>,
impl<T: RawEncodingBuf> From<i64> for TritBuf<T>where
T::Slice: RawEncoding<Trit = Btrit>,
sourceimpl<T: RawEncodingBuf> From<i8> for TritBuf<T>where
T::Slice: RawEncoding<Trit = Btrit>,
impl<T: RawEncodingBuf> From<i8> for TritBuf<T>where
T::Slice: RawEncoding<Trit = Btrit>,
sourceimpl<T: RawEncodingBuf> From<u128> for TritBuf<T>where
T::Slice: RawEncoding<Trit = Utrit>,
impl<T: RawEncodingBuf> From<u128> for TritBuf<T>where
T::Slice: RawEncoding<Trit = Utrit>,
sourceimpl<T: RawEncodingBuf> From<u16> for TritBuf<T>where
T::Slice: RawEncoding<Trit = Utrit>,
impl<T: RawEncodingBuf> From<u16> for TritBuf<T>where
T::Slice: RawEncoding<Trit = Utrit>,
sourceimpl<T: RawEncodingBuf> From<u32> for TritBuf<T>where
T::Slice: RawEncoding<Trit = Utrit>,
impl<T: RawEncodingBuf> From<u32> for TritBuf<T>where
T::Slice: RawEncoding<Trit = Utrit>,
sourceimpl<T: RawEncodingBuf> From<u64> for TritBuf<T>where
T::Slice: RawEncoding<Trit = Utrit>,
impl<T: RawEncodingBuf> From<u64> for TritBuf<T>where
T::Slice: RawEncoding<Trit = Utrit>,
sourceimpl<T: RawEncodingBuf> From<u8> for TritBuf<T>where
T::Slice: RawEncoding<Trit = Utrit>,
impl<T: RawEncodingBuf> From<u8> for TritBuf<T>where
T::Slice: RawEncoding<Trit = Utrit>,
sourceimpl<T: RawEncodingBuf> FromIterator<<<T as RawEncodingBuf>::Slice as RawEncoding>::Trit> for TritBuf<T>
impl<T: RawEncodingBuf> FromIterator<<<T as RawEncodingBuf>::Slice as RawEncoding>::Trit> for TritBuf<T>
sourcefn from_iter<I: IntoIterator<Item = <T::Slice as RawEncoding>::Trit>>(
iter: I
) -> Self
fn from_iter<I: IntoIterator<Item = <T::Slice as RawEncoding>::Trit>>(
iter: I
) -> Self
sourceimpl<T: RawEncodingBuf> Neg for TritBuf<T>where
T::Slice: RawEncoding<Trit = Btrit>,
impl<T: RawEncodingBuf> Neg for TritBuf<T>where
T::Slice: RawEncoding<Trit = Btrit>,
sourceimpl<T: RawEncodingBuf, U: RawEncodingBuf> PartialEq<TritBuf<U>> for TritBuf<T>where
T::Slice: RawEncoding,
U::Slice: RawEncoding<Trit = <T::Slice as RawEncoding>::Trit>,
impl<T: RawEncodingBuf, U: RawEncodingBuf> PartialEq<TritBuf<U>> for TritBuf<T>where
T::Slice: RawEncoding,
U::Slice: RawEncoding<Trit = <T::Slice as RawEncoding>::Trit>,
sourceimpl<T, U> PartialOrd<TritBuf<U>> for TritBuf<T>where
T: RawEncodingBuf,
U: RawEncodingBuf,
U::Slice: RawEncoding<Trit = <T::Slice as RawEncoding>::Trit>,
<T::Slice as RawEncoding>::Trit: PartialOrd,
impl<T, U> PartialOrd<TritBuf<U>> for TritBuf<T>where
T: RawEncodingBuf,
U: RawEncodingBuf,
U::Slice: RawEncoding<Trit = <T::Slice as RawEncoding>::Trit>,
<T::Slice as RawEncoding>::Trit: PartialOrd,
sourcefn partial_cmp(&self, other: &TritBuf<U>) -> Option<Ordering>
fn partial_cmp(&self, other: &TritBuf<U>) -> Option<Ordering>
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more