Skip to main content

libutils_array/
references.rs

1//^
2//^ HEAD
3//^
4
5//> HEAD -> SUPER
6use super::Array;
7
8//> HEAD -> CORE
9use core::{
10    slice::{
11        from_raw_parts as fat,
12        from_raw_parts_mut as mutfat
13    },
14    borrow::{
15        Borrow,
16        BorrowMut
17    }
18};
19
20
21//^
22//^ REFERENCES
23//^
24
25//> REFERENCES -> SLICE
26const impl<Type, const N: usize> AsRef<[Type]> for Array<Type, N> {
27    #[inline]
28    fn as_ref(&self) -> &[Type] {return unsafe {fat(self.data.as_ptr() as *const Type, self.length)}}
29}
30
31//> REFERENCES -> MUTABLE SLICE
32const impl<Type, const N: usize> AsMut<[Type]> for Array<Type, N> {
33    #[inline]
34    fn as_mut(&mut self) -> &mut [Type] {return unsafe {mutfat(self.pointer().as_ptr(), self.length)}}
35}
36
37
38//^
39//^ BORROW
40//^
41
42//> BORROW -> CONSTANT
43const impl<Type, const N: usize> Borrow<[Type]> for Array<Type, N> {
44    #[inline]
45    fn borrow(&self) -> &[Type] {self.as_ref()}
46}
47
48//> BORROW -> MUTABLE
49const impl<Type, const N: usize> BorrowMut<[Type]> for Array<Type, N> {
50    #[inline]
51    fn borrow_mut(&mut self) -> &mut [Type] {self.as_mut()}
52}