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
73
74
75
76
77
pub trait Vec2<T> {
    fn from_slice(slice: &[T; 2]) -> Self
    where
        Self: Sized;
    fn as_slice(&self) -> &[T; 2];
    fn as_ptr(&self) -> *const T;
}

impl<T> Vec2<T> for [T; 2]
where
    T: Copy,
    Self: Sized,
{
    fn from_slice(slice: &[T; 2]) -> [T; 2] {
        slice.clone()
    }

    fn as_slice(&self) -> &[T; 2] {
        self
    }

    fn as_ptr(&self) -> *const T {
        self as *const T
    }
}

pub trait Vec3<T>
where
    Self: Sized,
{
    fn from_slice(slice: &[T; 3]) -> Self;
    fn as_slice(&self) -> &[T; 3];
    fn as_ptr(&self) -> *const T;
}

impl<T> Vec3<T> for [T; 3]
where
    T: Copy,
{
    fn from_slice(slice: &[T; 3]) -> Self {
        slice.clone()
    }

    fn as_slice(&self) -> &[T; 3] {
        self
    }

    fn as_ptr(&self) -> *const T {
        self as *const T
    }
}

pub trait Vec4<T>
where
    Self: Sized,
{
    fn from_slice(slice: &[T; 4]) -> Self;
    fn as_slice(&self) -> &[T; 4];
    fn as_ptr(&self) -> *const T;
}

impl<T> Vec4<T> for [T; 4]
where
    T: Copy,
{
    fn from_slice(slice: &[T; 4]) -> Self {
        slice.clone()
    }

    fn as_slice(&self) -> &[T; 4] {
        self
    }

    fn as_ptr(&self) -> *const T {
        self as *const T
    }
}