MCPcopy Create free account
hub / github.com/Lokathor/tinyvec / Array

Interface Array

src/array.rs:16–39  ·  view source on GitHub ↗

A trait for types that are an array. An "array", for our purposes, has the following properties: Owns some number of elements. The element type can be generic, but must implement [`Default`]. The capacity is fixed at compile time, based on the implementing type. You can get a shared or mutable slice to the elements. You are generally **not** expected to need to implement this yourself. It is alr

Source from the content-addressed store, hash-verified

14/// Just a reminder: this trait is 100% safe, which means that `unsafe` code
15/// **must not** rely on an instance of this trait being correct.
16pub trait Array {
17 /// The type of the items in the thing.
18 type Item: Default;
19
20 /// The number of slots in the thing.
21 const CAPACITY: usize;
22
23 /// Gives a shared slice over the whole thing.
24 ///
25 /// A correct implementation will return a slice with a length equal to the
26 /// `CAPACITY` value.
27 fn as_slice(&self) -> &[Self::Item];
28
29 /// Gives a unique slice over the whole thing.
30 ///
31 /// A correct implementation will return a slice with a length equal to the
32 /// `CAPACITY` value.
33 fn as_slice_mut(&mut self) -> &mut [Self::Item];
34
35 /// Create a default-initialized instance of ourself, similar to the
36 /// [`Default`] trait, but implemented for the same range of sizes as
37 /// [`Array`].
38 fn default() -> Self;
39}
40
41mod const_generic_impl;
42

Callers

nothing calls this directly

Implementers 2

generic_array_impl.rssrc/array/generic_array_impl.rs
const_generic_impl.rssrc/array/const_generic_impl.rs

Calls

no outgoing calls

Tested by

no test coverage detected