-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreferences.rs
More file actions
72 lines (58 loc) · 1.37 KB
/
Copy pathreferences.rs
File metadata and controls
72 lines (58 loc) · 1.37 KB
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
64
65
66
67
68
69
70
71
72
//^
//^ HEAD
//^
//> HEAD -> SUPER
use super::Array;
//> HEAD -> CORE
use core::{
slice::{
from_raw_parts as fat,
from_raw_parts_mut as mutfat
},
borrow::{
Borrow,
BorrowMut
},
ops::{
Deref,
DerefMut
}
};
//^
//^ DEREF
//^
//> DEREF -> CONSTANT
const impl<Type, const N: usize> Deref for Array<Type, N> {
type Target = [Type];
fn deref(&self) -> &Self::Target {
return unsafe {fat(self.data.as_ptr().cast(), self.length)};
}
}
//> DEREF -> MUTABLE
const impl<Type, const N: usize> DerefMut for Array<Type, N> {
fn deref_mut(&mut self) -> &mut Self::Target {
return unsafe {mutfat(self.data.as_mut_ptr().cast(), self.length)};
}
}
//^
//^ REFERENCES
//^
//> REFERENCES -> SLICE
const impl<Type, const N: usize> AsRef<[Type]> for Array<Type, N> {
fn as_ref(&self) -> &[Type] {return self.deref()}
}
//> REFERENCES -> MUTABLE SLICE
const impl<Type, const N: usize> AsMut<[Type]> for Array<Type, N> {
fn as_mut(&mut self) -> &mut [Type] {return self.deref_mut()}
}
//^
//^ BORROW
//^
//> BORROW -> CONSTANT
const impl<Type, const N: usize> Borrow<[Type]> for Array<Type, N> {
fn borrow(&self) -> &[Type] {self.as_ref()}
}
//> BORROW -> MUTABLE
const impl<Type, const N: usize> BorrowMut<[Type]> for Array<Type, N> {
fn borrow_mut(&mut self) -> &mut [Type] {self.as_mut()}
}