1
1
// SPDX-License-Identifier: Apache-2.0
2
2
3
+ use core:: borrow:: { Borrow , BorrowMut } ;
3
4
use core:: mem:: { align_of, align_of_val, size_of, size_of_val} ;
5
+ use core:: ops:: { Deref , DerefMut } ;
4
6
5
7
/// A single page of memory
6
8
///
@@ -15,23 +17,56 @@ impl const_default::ConstDefault for Page {
15
17
}
16
18
17
19
impl Default for Page {
20
+ #[ inline]
18
21
fn default ( ) -> Self {
19
- Self ( [ [ 0 ; 32 ] ; 16 ] )
22
+ Self :: zeroed ( )
23
+ }
24
+ }
25
+
26
+ impl Deref for Page {
27
+ type Target = [ u8 ] ;
28
+
29
+ #[ inline]
30
+ fn deref ( & self ) -> & Self :: Target {
31
+ unsafe { self . 0 . align_to ( ) . 1 }
32
+ }
33
+ }
34
+
35
+ impl DerefMut for Page {
36
+ #[ inline]
37
+ fn deref_mut ( & mut self ) -> & mut Self :: Target {
38
+ unsafe { self . 0 . align_to_mut ( ) . 1 }
20
39
}
21
40
}
22
41
23
42
impl AsRef < [ u8 ] > for Page {
43
+ #[ inline]
24
44
fn as_ref ( & self ) -> & [ u8 ] {
25
45
unsafe { self . 0 . align_to ( ) . 1 }
26
46
}
27
47
}
28
48
29
49
impl AsMut < [ u8 ] > for Page {
50
+ #[ inline]
30
51
fn as_mut ( & mut self ) -> & mut [ u8 ] {
31
52
unsafe { self . 0 . align_to_mut ( ) . 1 }
32
53
}
33
54
}
34
55
56
+ impl Borrow < [ u8 ] > for Page {
57
+ #[ inline]
58
+ fn borrow ( & self ) -> & [ u8 ] {
59
+ unsafe { self . 0 . align_to ( ) . 1 }
60
+ }
61
+ }
62
+
63
+ impl BorrowMut < [ u8 ] > for Page {
64
+ #[ inline]
65
+ fn borrow_mut ( & mut self ) -> & mut [ u8 ] {
66
+ unsafe { self . 0 . align_to_mut ( ) . 1 }
67
+ }
68
+ }
69
+
35
70
impl Page {
36
71
/// Returns the size of the page in bytes
37
72
pub const fn size ( ) -> usize {
0 commit comments