[−][src]Struct bee_ternary::TritBuf
A buffer containing trits.
This type is roughly analogous to Vec
or String
. It supports pushing and popping trits
and dereferences to Trits
. It may be borrowed as a trit slice, either mutably or immutably.
Implementations
impl<T: RawEncodingBuf> TritBuf<T>
[src]
pub fn new() -> Self
[src]
Create a new empty TritBuf
.
pub fn filled(len: usize, trit: <T::Slice as RawEncoding>::Trit) -> Self
[src]
Create a new TritBuf
of the given length, filled with copies of the provided trit.
pub fn zeros(len: usize) -> Self
[src]
Create a new TritBuf
of the given length, filled with zero trit.
pub fn from_trits(trits: &[<T::Slice as RawEncoding>::Trit]) -> Self
[src]
Create a new TritBuf
containing the trits from the given slice of trits.
pub fn push(&mut self, trit: <T::Slice as RawEncoding>::Trit)
[src]
Push a trit to the back of this TritBuf
.
pub fn pop(&mut self) -> Option<<T::Slice as RawEncoding>::Trit>
[src]
Pop a trit from the back of this TritBuf
, returning it if successful.
pub fn as_slice(&self) -> &Trits<T::Slice>
[src]
Extracts a trit slice containing the data within this buffer.
Note that TritBuf
dereferences to Trits
anyway, so it's usually sufficient to take
a reference to TritBuf
or to just call &Trits
methods on it rather than explicitly
calling this method first.
pub fn as_slice_mut(&mut self) -> &mut Trits<T::Slice>
[src]
impl TritBuf<T3B1Buf>
[src]
pub fn pad_zeros(&mut self)
[src]
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 [Trites::as_trytes
].
pub fn padded_zeros(self) -> Self
[src]
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 [Trites::as_trytes
].
impl<T: RawEncodingBuf> TritBuf<T> where
T::Slice: RawEncoding<Trit = Btrit>,
[src]
T::Slice: RawEncoding<Trit = Btrit>,
pub fn from_i8s(trits: &[i8]) -> Result<Self, <Btrit as TryFrom<i8>>::Error>
[src]
Create a new TritBuf
containing the trits given by the slice of i8s.
impl<T: RawEncodingBuf> TritBuf<T> where
T::Slice: RawEncoding<Trit = Utrit>,
[src]
T::Slice: RawEncoding<Trit = Utrit>,
pub fn from_u8s(trits: &[u8]) -> Result<Self, <Btrit as TryFrom<u8>>::Error>
[src]
Create a new TritBuf
containing the trits given by the slice of u8s.
impl<T> TritBuf<T1B1Buf<T>> where
T: Trit,
T::Target: Trit,
[src]
T: Trit,
T::Target: Trit,
pub fn into_shifted(self) -> TritBuf<T1B1Buf<<T as ShiftTernary>::Target>>
[src]
Methods from Deref<Target = Trits<T::Slice>>
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::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::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::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::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<Item = T::Trit> + ExactSizeIterator<Item = T::Trit> + '_
[src]
&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.
pub fn subslice(&self, range: Range<usize>) -> &Self
[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 Self
[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: RawEncoding<Trit = T::Trit> + ?Sized>(
&mut self,
trits: &Trits<U>
)
[src]
&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.
pub fn fill(&mut self, trit: T::Trit)
[src]
Fill this mutable trit slice with copied of the given trit.
pub fn to_buf<U: RawEncodingBuf<Slice = T>>(&self) -> TritBuf<U>
[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<Item = &Self> + ExactSizeIterator<Item = &Self> + '_
[src]
&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>,
[src]
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> + '_
[src]
&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.
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 Self> + '_
[src]
&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
.
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]
Trait Implementations
impl<T: RawEncodingBuf> Borrow<Trits<<T as RawEncodingBuf>::Slice>> for TritBuf<T>
[src]
impl<T: RawEncodingBuf> BorrowMut<Trits<<T as RawEncodingBuf>::Slice>> for TritBuf<T>
[src]
fn borrow_mut(&mut self) -> &mut Trits<T::Slice>
[src]
impl<T: Clone + RawEncodingBuf> Clone for TritBuf<T>
[src]
impl<T: RawEncodingBuf> Debug for TritBuf<T>
[src]
impl<T: RawEncodingBuf> Default for TritBuf<T>
[src]
impl<T: RawEncodingBuf> Deref for TritBuf<T>
[src]
type Target = Trits<T::Slice>
The resulting type after dereferencing.
fn deref(&self) -> &Self::Target
[src]
impl<T: RawEncodingBuf> DerefMut for TritBuf<T>
[src]
impl<T: RawEncodingBuf> Display for TritBuf<T>
[src]
impl<T: RawEncodingBuf> From<i128> for TritBuf<T> where
T::Slice: RawEncoding<Trit = Btrit>,
[src]
T::Slice: RawEncoding<Trit = Btrit>,
impl<T: RawEncodingBuf> From<i16> for TritBuf<T> where
T::Slice: RawEncoding<Trit = Btrit>,
[src]
T::Slice: RawEncoding<Trit = Btrit>,
impl<T: RawEncodingBuf> From<i32> for TritBuf<T> where
T::Slice: RawEncoding<Trit = Btrit>,
[src]
T::Slice: RawEncoding<Trit = Btrit>,
impl<T: RawEncodingBuf> From<i64> for TritBuf<T> where
T::Slice: RawEncoding<Trit = Btrit>,
[src]
T::Slice: RawEncoding<Trit = Btrit>,
impl<T: RawEncodingBuf> From<i8> for TritBuf<T> where
T::Slice: RawEncoding<Trit = Btrit>,
[src]
T::Slice: RawEncoding<Trit = Btrit>,
impl<T: RawEncodingBuf> From<u128> for TritBuf<T> where
T::Slice: RawEncoding<Trit = Utrit>,
[src]
T::Slice: RawEncoding<Trit = Utrit>,
impl<T: RawEncodingBuf> From<u16> for TritBuf<T> where
T::Slice: RawEncoding<Trit = Utrit>,
[src]
T::Slice: RawEncoding<Trit = Utrit>,
impl<T: RawEncodingBuf> From<u32> for TritBuf<T> where
T::Slice: RawEncoding<Trit = Utrit>,
[src]
T::Slice: RawEncoding<Trit = Utrit>,
impl<T: RawEncodingBuf> From<u64> for TritBuf<T> where
T::Slice: RawEncoding<Trit = Utrit>,
[src]
T::Slice: RawEncoding<Trit = Utrit>,
impl<T: RawEncodingBuf> From<u8> for TritBuf<T> where
T::Slice: RawEncoding<Trit = Utrit>,
[src]
T::Slice: RawEncoding<Trit = Utrit>,
impl<T: RawEncodingBuf> FromIterator<<<T as RawEncodingBuf>::Slice as RawEncoding>::Trit> for TritBuf<T>
[src]
fn from_iter<I: IntoIterator<Item = <T::Slice as RawEncoding>::Trit>>(
iter: I
) -> Self
[src]
iter: I
) -> Self
impl<T> Hash for TritBuf<T> where
T: RawEncodingBuf,
T::Slice: Hash,
[src]
T: RawEncodingBuf,
T::Slice: Hash,
fn hash<H: Hasher>(&self, hasher: &mut H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<T: RawEncodingBuf> Neg for TritBuf<T> where
T::Slice: RawEncoding<Trit = Btrit>,
[src]
T::Slice: RawEncoding<Trit = Btrit>,
impl<T: RawEncodingBuf, U: RawEncodingBuf> PartialEq<TritBuf<U>> for TritBuf<T> where
T::Slice: RawEncoding,
U::Slice: RawEncoding<Trit = <T::Slice as RawEncoding>::Trit>,
[src]
T::Slice: RawEncoding,
U::Slice: RawEncoding<Trit = <T::Slice as RawEncoding>::Trit>,
Auto Trait Implementations
impl<T> RefUnwindSafe for TritBuf<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for TritBuf<T> where
T: Send,
T: Send,
impl<T> Sync for TritBuf<T> where
T: Sync,
T: Sync,
impl<T> Unpin for TritBuf<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for TritBuf<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,