Trait ByteArray

Source
pub unsafe trait ByteArray: Array<Item = u8> {
    const DEFAULT: Self;
}
Available on crate feature tiny_container only.
Expand description

An array type containing bytes.

Because tinyvec_string has unsafe and tinyvec doesn’t, this trait is required for soundness. unsafe code can depend on an unsafe trait, and tinyvec::Array is not unsafe.

The provided implementations of ByteArray for various sizes of [u8; N] follow this trait’s contract, and it shouldn’t be necessary to add implementations for other types in most cases.

Implementations are provided for [u8; N] for N <= 32 and powers of 2 <= 4096. Other implementations could be provided on request.

Like tinyvec, tinyvec_string’s rustc_1_55 feature provides implementations for u8 arrays of all sizes.

§Safety

Any types that implement this trait must have tinyvec::Array implementations that always return the same slices; i.e. between calls of as_slice or as_slice_mut, the implementation of the trait must not modify the contents of the slice (directly or indirectly) or return a slice with different contents. They must also always return slices with a length of CAPACITY.

Any implementations must also follow the stated contract of DEFAULT.

Any implementations that do not follow the above may cause memory safety errors within ArrayString or TinyString.

Required Associated Constants§

Source

const DEFAULT: Self

Default value of the array.

This MUST be an array with length CAPACITY with all zero elements.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<const N: usize> ByteArray for [u8; N]

Available on crate feature rustc_1_55 only.
Source§

const DEFAULT: [u8; N]

Implementors§