@@ -4,17 +4,19 @@ use core::{
44 self ,
55 MaybeUninit ,
66 } ,
7- ops:: Deref ,
7+ ops:: {
8+ Deref ,
9+ DerefMut ,
10+ } ,
811 slice,
912} ;
1013
1114use crate :: {
12- CopyConstructable ,
15+ memory :: FromMemoryView ,
1316 MemoryView ,
1417 OutOfBoundsViolation ,
1518 Reference ,
16- SizedViewable ,
17- ViewableImplementation ,
19+ ViewableSized ,
1820} ;
1921
2022#[ derive( Clone , Copy ) ]
@@ -32,15 +34,15 @@ impl<M: marker::Copy> MemoryView for CopyMemory<M> {
3234}
3335
3436/// A Copy represents an owned copy of the struct binary contents
35- #[ repr ( transparent ) ]
36- pub struct Copy < T : SizedViewable > {
37- inner : T :: Implementation < CopyMemory < T :: Memory > > ,
37+ #[ derive ( Clone ) ]
38+ pub struct Copy < V : ViewableSized > {
39+ inner : Reference < V , CopyMemory < V :: Memory > > ,
3840}
3941
40- impl < T : SizedViewable > Copy < T > {
41- pub fn new ( inner : T :: Memory ) -> Self {
42+ impl < V : ViewableSized > Copy < V > {
43+ pub fn new ( inner : V :: Memory ) -> Self {
4244 Self {
43- inner : T :: from_memory ( CopyMemory ( inner) ) ,
45+ inner : Reference :: new ( CopyMemory ( inner) , 0x00 ) ,
4446 }
4547 }
4648
@@ -55,52 +57,56 @@ impl<T: SizedViewable> Copy<T> {
5557 memory : & M ,
5658 offset : u64 ,
5759 ) -> Result < Self , M :: AccessError > {
58- let mut copy_memory = MaybeUninit :: < T :: Memory > :: uninit ( ) ;
59- memory. read_memory ( offset, unsafe {
60- slice:: from_raw_parts_mut (
61- copy_memory. as_mut_ptr ( ) as * mut u8 ,
62- mem:: size_of :: < T :: Memory > ( ) ,
63- )
64- } ) ?;
65-
66- Ok ( Self :: new ( unsafe { copy_memory. assume_init ( ) } ) )
67- }
68-
69- pub fn as_reference ( & self ) -> Reference < T , & CopyMemory < T :: Memory > > {
70- Reference :: new ( self . inner . memory_view ( ) , 0x00 )
71- }
72- }
73-
74- impl < T > Clone for Copy < T >
75- where
76- T : SizedViewable ,
77- T :: Implementation < CopyMemory < T :: Memory > > : Clone ,
78- {
79- fn clone ( & self ) -> Self {
80- Self {
81- inner : self . inner . clone ( ) ,
82- }
60+ Ok ( Self :: new (
61+ V :: Memory :: read_object ( memory, offset) . map_err ( |err| err. into_access_error ( ) ) ?,
62+ ) )
8363 }
8464}
8565
86- impl < T > marker:: Copy for Copy < T >
87- where
88- T : SizedViewable ,
89- T :: Implementation < CopyMemory < T :: Memory > > : marker:: Copy ,
90- {
91- }
92-
93- impl < T > CopyConstructable for Copy < T >
94- where
95- T : SizedViewable ,
96- T :: Implementation < CopyMemory < T :: Memory > > : marker:: Copy ,
97- {
98- }
99-
100- impl < T : SizedViewable > Deref for Copy < T > {
101- type Target = T :: Implementation < CopyMemory < T :: Memory > > ;
66+ impl < V : ViewableSized > Deref for Copy < V > {
67+ type Target = Reference < V , CopyMemory < V :: Memory > > ;
10268
10369 fn deref ( & self ) -> & Self :: Target {
10470 & self . inner
10571 }
10672}
73+
74+ impl < V : ViewableSized > DerefMut for Copy < V > {
75+ fn deref_mut ( & mut self ) -> & mut Self :: Target {
76+ & mut self . inner
77+ }
78+ }
79+
80+ // impl<T> Clone for Copy<T>
81+ // where
82+ // T: SizedViewable,
83+ // T::Implementation<CopyMemory<T::Memory>>: Clone,
84+ // {
85+ // fn clone(&self) -> Self {
86+ // Self {
87+ // inner: self.inner.clone(),
88+ // }
89+ // }
90+ // }
91+
92+ // impl<T> marker::Copy for Copy<T>
93+ // where
94+ // T: SizedViewable,
95+ // T::Implementation<CopyMemory<T::Memory>>: marker::Copy,
96+ // {
97+ // }
98+
99+ // impl<T> CopyConstructable for Copy<T>
100+ // where
101+ // T: SizedViewable,
102+ // T::Implementation<CopyMemory<T::Memory>>: marker::Copy,
103+ // {
104+ // }
105+
106+ // impl<T: SizedViewable> Deref for Copy<T> {
107+ // type Target = T::Implementation<CopyMemory<T::Memory>>;
108+
109+ // fn deref(&self) -> &Self::Target {
110+ // &self.inner
111+ // }
112+ // }
0 commit comments