dynamic_list/array/
traits.rs

1use crate::array::Node;
2use crate::{Empty, Length, NotEmpty};
3use std::mem::size_of;
4
5pub trait ArrayAppend {
6    type Output<T>;
7}
8impl ArrayAppend for Empty {
9    type Output<T> = Node<T>;
10}
11impl<V, N: ArrayAppend> ArrayAppend for Node<V, N> {
12    type Output<T> = Node<V, N::Output<T>>;
13}
14
15pub trait MemorySize {
16    const SIZE: usize = 0;
17}
18impl MemorySize for Empty {}
19impl<V, N: MemorySize> MemorySize for Node<V, N> {
20    const SIZE: usize = size_of::<V>() + N::SIZE;
21}
22
23pub trait RemoveFirst {
24    type Element;
25    type Rest;
26}
27impl RemoveFirst for Empty {
28    type Element = Empty;
29    type Rest = Empty;
30}
31impl<V, N> RemoveFirst for Node<V, N> {
32    type Element = Node<V>;
33    type Rest = N;
34}
35
36impl<V> NotEmpty for Node<V> {}
37impl<V, N: NotEmpty> NotEmpty for Node<V, N> {}
38
39impl<V, N: Length> Length for Node<V, N> {
40    const SIZE: usize = 1 + N::SIZE;
41}