@@ -22,12 +22,8 @@ pub unsafe trait GetUncheckedMut : GetUnchecked {
22
22
}
23
23
24
24
pub unsafe trait ContiguousMut : Contiguous {
25
- fn begin_mut ( & self ) -> * mut Self :: Item {
26
- self . begin ( ) as _
27
- }
28
- fn end_mut ( & self ) -> * mut Self :: Item {
29
- self . end ( ) as _
30
- }
25
+ fn begin_mut ( & mut self ) -> * mut Self :: Item ;
26
+ fn end_mut ( & mut self ) -> * mut Self :: Item ;
31
27
fn as_mut_slice ( & mut self ) -> & mut [ Self :: Item ] ;
32
28
}
33
29
@@ -52,6 +48,8 @@ unsafe impl<'a, C: ?Sized> Trustworthy for &'a mut C
52
48
unsafe impl < ' a , C : ?Sized > ContiguousMut for & ' a mut C
53
49
where C : ContiguousMut
54
50
{
51
+ fn begin_mut ( & mut self ) -> * mut Self :: Item { ( * * self ) . begin_mut ( ) }
52
+ fn end_mut ( & mut self ) -> * mut Self :: Item { ( * * self ) . end_mut ( ) }
55
53
fn as_mut_slice ( & mut self ) -> & mut [ Self :: Item ] {
56
54
( * * self ) . as_mut_slice ( )
57
55
}
@@ -115,6 +113,14 @@ unsafe impl<T> Trustworthy for [T] {
115
113
}
116
114
117
115
unsafe impl < T > ContiguousMut for [ T ] {
116
+ fn begin_mut ( & mut self ) -> * mut Self :: Item {
117
+ self . as_mut_ptr ( )
118
+ }
119
+ fn end_mut ( & mut self ) -> * mut Self :: Item {
120
+ unsafe {
121
+ self . begin_mut ( ) . add ( self . len ( ) )
122
+ }
123
+ }
118
124
fn as_mut_slice ( & mut self ) -> & mut [ Self :: Item ] {
119
125
self
120
126
}
@@ -138,7 +144,7 @@ unsafe impl<T> Contiguous for [T] {
138
144
}
139
145
fn end ( & self ) -> * const Self :: Item {
140
146
unsafe {
141
- self . begin ( ) . offset ( self . len ( ) as isize )
147
+ self . begin ( ) . add ( self . len ( ) )
142
148
}
143
149
}
144
150
fn as_slice ( & self ) -> & [ Self :: Item ] {
@@ -155,6 +161,8 @@ mod vec_impls {
155
161
}
156
162
157
163
unsafe impl < T > ContiguousMut for Vec < T > {
164
+ fn begin_mut ( & mut self ) -> * mut Self :: Item { ( * * self ) . begin_mut ( ) }
165
+ fn end_mut ( & mut self ) -> * mut Self :: Item { ( * * self ) . end_mut ( ) }
158
166
fn as_mut_slice ( & mut self ) -> & mut [ Self :: Item ] {
159
167
self
160
168
}
0 commit comments