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
61
62
63
// devela/src/sys/mem/alloc/storage/traits.rs
//
//! Defines [`Storage`].
//
use crateDerefMut;
use crate::;
use crate::;
/// Allows data structures to be generic over their storage strategy.
/// There are two reference implementations:
/// - [`Bare`], storing data inline via [`BareBox`].
/// - [`Boxed`], storing data on the heap via [`Box`].
///
/// # Examples
/// ```
/// use core::array::from_fn;
/// use devela::Storage;
///
/// /// Generically store a generic array of generic size.
/// pub struct MyStructure<T, S: Storage, const L: usize> {
/// data: S::Stored<[T; L]>,
/// }
///
/// impl<T: Default, S: Storage, const L: usize> MyStructure<T, S, L> {
/// pub fn new() -> Self {
/// Self {
/// data: S::Stored::from(from_fn(|_| T::default())),
/// }
/// }
/// }
///
/// // The array is stored inline (stack-allocated).
/// assert_eq![100, size_of::<MyStructure::<u8, (), 100>>()];
///
/// // The array is stored in the heap.
/// #[cfg(feature = "alloc")]
/// {
/// #[cfg(target_pointer_width = "32")] let stack_size = 4;
/// #[cfg(target_pointer_width = "64")] let stack_size = 8;
/// assert_eq![stack_size, size_of::<MyStructure::<u8, devela::Boxed, 100>>()];
/// }
/// ```