@@ -64,6 +64,24 @@ pub unsafe trait DataRawMut : DataRaw {
6464 fn try_is_unique ( & mut self ) -> Option < bool > ;
6565}
6666
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+
6785/// Array representation trait.
6886///
6987/// For an array with elements that can be accessed with safe code.
@@ -111,21 +129,13 @@ pub unsafe trait DataMut : Data + DataRawMut {
111129
112130/// Array representation trait.
113131///
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.
115134///
116135/// ***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 { }
121137
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 { }
129139
130140unsafe impl < A > DataRaw for RawViewRepr < * const A > {
131141 type Elem = A ;
@@ -135,6 +145,12 @@ unsafe impl<A> DataRaw for RawViewRepr<*const A> {
135145 private_impl ! { }
136146}
137147
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+
138154unsafe impl < A > DataRaw for RawViewRepr < * mut A > {
139155 type Elem = A ;
140156 fn _data_slice ( & self ) -> Option < & [ A ] > {
@@ -156,6 +172,12 @@ unsafe impl<A> DataRawMut for RawViewRepr<*mut A> {
156172 }
157173}
158174
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+
159181unsafe impl < A > DataRaw for OwnedArcRepr < A > {
160182 type Elem = A ;
161183 fn _data_slice ( & self ) -> Option < & [ A ] > {
@@ -222,7 +244,7 @@ unsafe impl<A> Data for OwnedArcRepr<A> {
222244
223245unsafe impl < A > DataMut for OwnedArcRepr < A > where A : Clone { }
224246
225- unsafe impl < A > DataClone for OwnedArcRepr < A > {
247+ unsafe impl < A > DataRawClone for OwnedArcRepr < A > {
226248 unsafe fn clone_with_ptr ( & self , ptr : * mut Self :: Elem ) -> ( Self , * mut Self :: Elem ) {
227249 // pointer is preserved
228250 ( self . clone ( ) , ptr)
@@ -263,7 +285,7 @@ unsafe impl<A> Data for OwnedRepr<A> {
263285
264286unsafe impl < A > DataMut for OwnedRepr < A > { }
265287
266- unsafe impl < A > DataClone for OwnedRepr < A >
288+ unsafe impl < A > DataRawClone for OwnedRepr < A >
267289 where A : Clone
268290{
269291 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> {
307329 }
308330}
309331
310- unsafe impl < ' a , A > DataClone for ViewRepr < & ' a A > {
332+ unsafe impl < ' a , A > DataRawClone for ViewRepr < & ' a A > {
311333 unsafe fn clone_with_ptr ( & self , ptr : * mut Self :: Elem ) -> ( Self , * mut Self :: Elem ) {
312334 ( * self , ptr)
313335 }
0 commit comments