osom_lib_arrays/inline_array/
immutable_inline_array.rs1use core::ops::Index;
2
3use osom_lib_alloc::traits::Allocator;
4use osom_lib_primitives::length::Length;
5
6use crate::traits::ImmutableArray;
7
8use super::InlineArray;
9
10impl<const TCAPACITY: usize, T, TAllocator> Default for InlineArray<TCAPACITY, T, TAllocator>
11where
12 T: Sized,
13 TAllocator: Allocator,
14{
15 #[inline(always)]
16 fn default() -> Self {
17 Self::new()
18 }
19}
20
21impl<const TCAPACITY: usize, T, TAllocator> Index<Length> for InlineArray<TCAPACITY, T, TAllocator>
22where
23 T: Sized,
24 TAllocator: Allocator,
25{
26 type Output = T;
27
28 fn index(&self, index: Length) -> &Self::Output {
29 &self.as_slice_internal()[index.as_usize()]
30 }
31}
32
33impl<const TCAPACITY: usize, T, TAllocator> ImmutableArray<T> for InlineArray<TCAPACITY, T, TAllocator>
34where
35 T: Sized,
36 TAllocator: Allocator,
37{
38 #[inline(always)]
39 fn length(&self) -> Length {
40 self.size
41 }
42
43 #[inline(always)]
44 fn capacity(&self) -> Length {
45 self.capacity
46 }
47
48 #[inline(always)]
49 fn as_slice(&self) -> &[T] {
50 self.as_slice_internal()
51 }
52}