#[repr(transparent)]
pub struct Trits<T: RawEncoding + ?Sized = T1B1<Btrit>>(_);
Expand description

A type that represents a buffer of trits of unknown length.

This type is roughly analogous to [T] or str. It is an unsized type and hence is rarely used directly. Instead, it’s more common to see it used from behind a reference (in a similar manner to &[T] and &str.

Implementations

Create an empty trit slice.

Interpret an (core::i8) slice as a trit slice with the given encoding without first checking that the slice is valid in the given encoding. The num_trits parameter is used to specify the exact length, in trits, that the slice should be taken to have. Providing a slice that is not valid for this encoding is undefined behaviour.

Panics

This function will panic if num_trits is more than can be represented with the slice in the given encoding.

Safety

This function must only be called with an i8 slice that is valid for this trit encoding given the specified num_trits length. Right now, this validity is not well-defined and so it is suggested that only i8 slices created from existing trit slices or trit buffers be used. Calling this function with an invalid i8 slice is undefined behaviour.

Interpret a mutable (core::i8) slice as a mutable trit slice with the given encoding without first checking that the slice is valid in the given encoding. The num_trits parameter is used to specify the exact length, in trits, that the slice should be taken to have. Providing a slice that is not valid for this encoding is undefined behaviour.

Panics

This function will panic if num_trits is more than can be represented with the slice in the given encoding.

Safety

This function must only be called with an i8 slice that is valid for this trit encoding given the specified num_trits length. Right now, this validity is not well-defined and so it is suggested that only i8 slices created from existing trit slices or trit buffers be used. Calling this function with an invalid i8 slice is undefined behaviour.

Interpret an (core::i8) slice as a trit slice with the given encoding, checking to ensure that the slice is valid in the given encoding. The num_trits parameter is used to specify the exact length, in trits, that the slice should be taken to have.

Panics

This function will panic if num_trits is more than can be represented with the slice in the given encoding.

Interpret a mutable (core::i8) slice as a mutable trit slice with the given encoding, checking to ensure that the slice is valid in the given encoding. The num_trits parameter is used to specify the exact length, in trits, that the slice should be taken to have.

Panics

This function will panic if num_trits is more than can be represented with the slice in the given encoding.

Returns true if the trit slice is empty.

Returns the number of trits in this trit slice.

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

Panics

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

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.

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.

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.

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.

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

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.

Negate each trit in this buffer.

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

These functions are only implemented for trit slices with the T1B1 encoding because other encodings are compressed and do not support handing out references to their internal trits. T1B1 is an exception because its trits are strictly byte-aligned.

This fact also implies that T1B1 is the fastest encoding for general-purpose manipulation of trits.

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.

These functions are only implemented for trit slices with the T3B1 encoding because only the T3B1 encoding has a representation compatible with a slice of Trytes. If you find yourself commonly needing to convert between trits and trytes, T3B1 is the encoding to use.

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.

Interpret this mutable trit slice as a mutable 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.

Trait Implementations

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

The returned type after indexing.

Performs the indexing (container[index]) operation. Read more

The returned type after indexing.

Performs the indexing (container[index]) operation. Read more

The returned type after indexing.

Performs the indexing (container[index]) operation. Read more

The returned type after indexing.

Performs the indexing (container[index]) operation. Read more

The returned type after indexing.

Performs the indexing (container[index]) operation. Read more

The returned type after indexing.

Performs the indexing (container[index]) operation. Read more

The returned type after indexing.

Performs the indexing (container[index]) operation. Read more

Performs the mutable indexing (container[index]) operation. Read more

Performs the mutable indexing (container[index]) operation. Read more

Performs the mutable indexing (container[index]) operation. Read more

Performs the mutable indexing (container[index]) operation. Read more

Performs the mutable indexing (container[index]) operation. Read more

Performs the mutable indexing (container[index]) operation. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Serialize this value into the given Serde serializer. Read more

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.