]>
git.proxmox.com Git - cargo.git/blob - vendor/tinyvec/src/array.rs
1 /// A trait for types that are an array.
3 /// An "array", for our purposes, has the following properties:
4 /// * Owns some number of elements.
5 /// * The element type can be generic, but must implement [`Default`].
6 /// * The capacity is fixed at compile time, based on the implementing type.
7 /// * You can get a shared or mutable slice to the elements.
9 /// You are generally **not** expected to need to implement this yourself. It is
10 /// already implemented for all the major array lengths (`0..=32` and the powers
11 /// of 2 up to 4,096).
13 /// **Additional lengths can easily be added upon request.**
15 /// ## Safety Reminder
17 /// Just a reminder: this trait is 100% safe, which means that `unsafe` code
18 /// **must not** rely on an instance of this trait being correct.
20 /// The type of the items in the thing.
23 /// The number of slots in the thing.
24 const CAPACITY
: usize;
26 /// Gives a shared slice over the whole thing.
28 /// A correct implementation will return a slice with a length equal to the
30 fn as_slice(&self) -> &[Self::Item
];
32 /// Gives a unique slice over the whole thing.
34 /// A correct implementation will return a slice with a length equal to the
36 fn as_slice_mut(&mut self) -> &mut [Self::Item
];
38 /// Create a default-initialized instance of ourself, similar to the
39 /// [`Default`] trait, but implemented for the same range of sizes as
44 #[cfg(feature = "nightly_const_generics")]
45 mod const_generic_impl
;
47 #[cfg(not(feature = "nightly_const_generics"))]