1/// A trait for types that are an array.
2///
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.
8///
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), or for all array lengths with the feature `rustc_1_55`.
12///
13/// **Additional lengths can easily be added upon request.**
14///
15/// ## Safety Reminder
16///
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.
19pub trait Array {
20 /// The type of the items in the thing.
21 type Item: Default;
22
23 /// The number of slots in the thing.
24 const CAPACITY: usize;
25
26 /// Gives a shared slice over the whole thing.
27 ///
28 /// A correct implementation will return a slice with a length equal to the
29 /// `CAPACITY` value.
30 fn as_slice(&self) -> &[Self::Item];
31
32 /// Gives a unique slice over the whole thing.
33 ///
34 /// A correct implementation will return a slice with a length equal to the
35 /// `CAPACITY` value.
36 fn as_slice_mut(&mut self) -> &mut [Self::Item];
37
38 /// Create a default-initialized instance of ourself, similar to the
39 /// [`Default`] trait, but implemented for the same range of sizes as
40 /// [`Array`].
41 fn default() -> Self;
42}
43
44#[cfg(feature = "rustc_1_55")]
45mod const_generic_impl;
46
47#[cfg(not(feature = "rustc_1_55"))]
48mod generated_impl;
49