@@ -64,6 +64,24 @@ pub unsafe trait DataRawMut : DataRaw {
64
64
fn try_is_unique ( & mut self ) -> Option < bool > ;
65
65
}
66
66
67
+ /// Array representation trait.
68
+ ///
69
+ /// An array representation that can be cloned.
70
+ ///
71
+ /// ***Internal trait, see `DataRaw`.***
72
+ pub unsafe trait DataRawClone : DataRaw {
73
+ #[ doc( hidden) ]
74
+ /// Unsafe because, `ptr` must point inside the current storage.
75
+ unsafe fn clone_with_ptr ( & self , ptr : * mut Self :: Elem ) -> ( Self , * mut Self :: Elem ) ;
76
+
77
+ #[ doc( hidden) ]
78
+ unsafe fn clone_from_with_ptr ( & mut self , other : & Self , ptr : * mut Self :: Elem ) -> * mut Self :: Elem {
79
+ let ( data, ptr) = other. clone_with_ptr ( ptr) ;
80
+ * self = data;
81
+ ptr
82
+ }
83
+ }
84
+
67
85
/// Array representation trait.
68
86
///
69
87
/// For an array with elements that can be accessed with safe code.
@@ -111,21 +129,13 @@ pub unsafe trait DataMut : Data + DataRawMut {
111
129
112
130
/// Array representation trait.
113
131
///
114
- /// An array representation that can be cloned.
132
+ /// An array representation that can be cloned and allows elements to be
133
+ /// accessed with safe code.
115
134
///
116
135
/// ***Internal trait, see `Data`.***
117
- pub unsafe trait DataClone : Data {
118
- #[ doc( hidden) ]
119
- /// Unsafe because, `ptr` must point inside the current storage.
120
- unsafe fn clone_with_ptr ( & self , ptr : * mut Self :: Elem ) -> ( Self , * mut Self :: Elem ) ;
136
+ pub trait DataClone : Data + DataRawClone { }
121
137
122
- #[ doc( hidden) ]
123
- unsafe fn clone_from_with_ptr ( & mut self , other : & Self , ptr : * mut Self :: Elem ) -> * mut Self :: Elem {
124
- let ( data, ptr) = other. clone_with_ptr ( ptr) ;
125
- * self = data;
126
- ptr
127
- }
128
- }
138
+ impl < T > DataClone for T where T : Data + DataRawClone { }
129
139
130
140
unsafe impl < A > DataRaw for RawViewRepr < * const A > {
131
141
type Elem = A ;
@@ -135,6 +145,12 @@ unsafe impl<A> DataRaw for RawViewRepr<*const A> {
135
145
private_impl ! { }
136
146
}
137
147
148
+ unsafe impl < A > DataRawClone for RawViewRepr < * const A > {
149
+ unsafe fn clone_with_ptr ( & self , ptr : * mut Self :: Elem ) -> ( Self , * mut Self :: Elem ) {
150
+ ( * self , ptr)
151
+ }
152
+ }
153
+
138
154
unsafe impl < A > DataRaw for RawViewRepr < * mut A > {
139
155
type Elem = A ;
140
156
fn _data_slice ( & self ) -> Option < & [ A ] > {
@@ -156,6 +172,12 @@ unsafe impl<A> DataRawMut for RawViewRepr<*mut A> {
156
172
}
157
173
}
158
174
175
+ unsafe impl < A > DataRawClone for RawViewRepr < * mut A > {
176
+ unsafe fn clone_with_ptr ( & self , ptr : * mut Self :: Elem ) -> ( Self , * mut Self :: Elem ) {
177
+ ( * self , ptr)
178
+ }
179
+ }
180
+
159
181
unsafe impl < A > DataRaw for OwnedArcRepr < A > {
160
182
type Elem = A ;
161
183
fn _data_slice ( & self ) -> Option < & [ A ] > {
@@ -222,7 +244,7 @@ unsafe impl<A> Data for OwnedArcRepr<A> {
222
244
223
245
unsafe impl < A > DataMut for OwnedArcRepr < A > where A : Clone { }
224
246
225
- unsafe impl < A > DataClone for OwnedArcRepr < A > {
247
+ unsafe impl < A > DataRawClone for OwnedArcRepr < A > {
226
248
unsafe fn clone_with_ptr ( & self , ptr : * mut Self :: Elem ) -> ( Self , * mut Self :: Elem ) {
227
249
// pointer is preserved
228
250
( self . clone ( ) , ptr)
@@ -263,7 +285,7 @@ unsafe impl<A> Data for OwnedRepr<A> {
263
285
264
286
unsafe impl < A > DataMut for OwnedRepr < A > { }
265
287
266
- unsafe impl < A > DataClone for OwnedRepr < A >
288
+ unsafe impl < A > DataRawClone for OwnedRepr < A >
267
289
where A : Clone
268
290
{
269
291
unsafe fn clone_with_ptr ( & self , ptr : * mut Self :: Elem ) -> ( Self , * mut Self :: Elem ) {
@@ -307,7 +329,7 @@ unsafe impl<'a, A> Data for ViewRepr<&'a A> {
307
329
}
308
330
}
309
331
310
- unsafe impl < ' a , A > DataClone for ViewRepr < & ' a A > {
332
+ unsafe impl < ' a , A > DataRawClone for ViewRepr < & ' a A > {
311
333
unsafe fn clone_with_ptr ( & self , ptr : * mut Self :: Elem ) -> ( Self , * mut Self :: Elem ) {
312
334
( * self , ptr)
313
335
}
0 commit comments