Struct bee_ternary::TritBuf [−][src]
#[repr(transparent)]pub struct TritBuf<T: RawEncodingBuf = T1B1Buf<Btrit>>(_);
Expand description
Implementations
Create a new TritBuf
of the given length, filled with copies of the provided trit.
Create a new TritBuf
of the given length, filled with zero trit.
Create a new TritBuf
containing the trits from the given slice of trits.
Clears the buffer, removing all values. Note that this method has no effect on the allocated capacity of the buffer.
Push a trit to the back of this TritBuf
.
Pop a trit from the back of this TritBuf
, returning it if successful.
pub 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
.
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
.
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
.
Methods from Deref<Target = Trits<T::Slice>>
Interpret this slice as an (std::i8
) slice.
Panics
This function will panic if the slice is not byte-aligned.
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.
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.
Fetch the trit at the given index of this trit slice, if the index is valid.
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<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.
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.
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.
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.
Fill this mutable trit slice with copied of the given trit.
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<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
.
pub 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.
pub 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.
View this trit slice as an ordinary slice of trits.
View this mutable trit slice as an ordinary slice of mutable trits.
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
.
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
Mutably borrows from an owned value. Read more
impl<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>
Creates a value from an iterator. Read more
impl<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>,
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,
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,
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Auto Trait Implementations
impl<T> RefUnwindSafe for TritBuf<T> where
T: RefUnwindSafe,
impl<T> UnwindSafe for TritBuf<T> where
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more