1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//! Trait for byte arrays.
/// 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`.
///
/// [`tinyvec::Array`]: ../tinyvec/trait.Array.html
pub unsafe
impl_bytearray_for_len!
unsafe