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
use std_::marker::PhantomData;
#[repr(transparent)]
#[derive(Debug)]
pub struct MutRef<'a,T:?Sized>{
pub ptr:*mut T,
_marker:PhantomData<&'a mut T>,
}
impl<'a,T:?Sized> Copy for MutRef<'a,T>{}
impl<'a,T:?Sized> Clone for MutRef<'a,T>{
#[inline(always)]
fn clone(&self)->Self{
*self
}
}
impl<'a,T:?Sized> MutRef<'a,T>{
#[inline(always)]
pub fn new(mut_ref:&'a mut T)->Self{
Self{
ptr:mut_ref,
_marker:PhantomData,
}
}
#[inline(always)]
pub fn from_ptr(ptr:*mut T)->Self{
Self{
ptr,
_marker:PhantomData,
}
}
#[inline(always)]
pub fn cast<U>(self)->MutRef<'a,U>{
MutRef{
ptr:self.ptr as *mut U,
_marker:PhantomData,
}
}
}
impl<'a,T:?Sized> From<&'a mut T> for MutRef<'a,T>{
#[inline(always)]
fn from(mutref:&'a mut T)->Self{
Self::new(mutref)
}
}