@@ -60,41 +60,64 @@ impl PodValType<{ mem::size_of::<V128>() }> for V128 {
6060/// for preserving the memory safety of indexed GC heaps in the face of (for
6161/// example) collector bugs, but the latter is just a defensive technique to
6262/// catch bugs early and prevent action at a distance as much as possible.
63- pub struct VMGcObjectDataMut < ' a > {
64- data : & ' a mut [ u8 ] ,
63+ #[ repr( transparent) ]
64+ pub struct VMGcObjectData {
65+ data : [ u8 ] ,
6566}
6667
6768macro_rules! impl_pod_methods {
68- ( $( $t : ty, $read: ident, $write: ident; ) * ) => {
69+ ( $( $T : ty, $read: ident, $write: ident; ) * ) => {
6970 $(
7071 /// Read a `
71- #[ doc = stringify!( $t ) ]
72+ #[ doc = stringify!( $T ) ]
7273 /// ` field this object.
7374 ///
7475 /// Panics on out-of-bounds accesses.
7576 #[ inline]
76- pub fn $read( & self , offset: u32 ) -> $t {
77- self . read_pod:: <{ mem:: size_of:: <$t>( ) } , $t>( offset)
77+ pub fn $read( & self , offset: u32 ) -> $T
78+ {
79+ self . read_pod:: <{ mem:: size_of:: <$T>( ) } , $T>( offset)
7880 }
7981
8082 /// Write a `
81- #[ doc = stringify!( $t ) ]
83+ #[ doc = stringify!( $T ) ]
8284 /// ` into this object.
8385 ///
8486 /// Panics on out-of-bounds accesses.
8587 #[ inline]
86- pub fn $write( & mut self , offset: u32 , val: $t) {
87- self . write_pod:: <{ mem:: size_of:: <$t>( ) } , $t>( offset, val) ;
88+ pub fn $write( & mut self , offset: u32 , val: $T)
89+ {
90+ self . write_pod:: <{ mem:: size_of:: <$T>( ) } , $T>( offset, val) ;
8891 }
8992 ) *
9093 } ;
9194}
9295
93- impl < ' a > VMGcObjectDataMut < ' a > {
94- /// Construct a `VMStructDataMut` from the given slice of bytes.
96+ impl < ' a > From < & ' a [ u8 ] > for & ' a VMGcObjectData {
9597 #[ inline]
96- pub fn new ( data : & ' a mut [ u8 ] ) -> Self {
97- Self { data }
98+ fn from ( data : & ' a [ u8 ] ) -> Self {
99+ & VMGcObjectData :: from_slice ( data)
100+ }
101+ }
102+
103+ impl < ' a > From < & ' a mut [ u8 ] > for & ' a mut VMGcObjectData {
104+ #[ inline]
105+ fn from ( data : & ' a mut [ u8 ] ) -> Self {
106+ VMGcObjectData :: from_slice_mut ( data)
107+ }
108+ }
109+
110+ impl VMGcObjectData {
111+ /// Construct a `VMGcObjectData` from the given slice of bytes.
112+ #[ inline]
113+ pub fn from_slice ( data : & [ u8 ] ) -> & Self {
114+ unsafe { mem:: transmute ( data) }
115+ }
116+
117+ /// Construct a `VMGcObjectData` from the given slice of bytes.
118+ #[ inline]
119+ pub fn from_slice_mut ( data : & mut [ u8 ] ) -> & mut Self {
120+ unsafe { mem:: transmute ( data) }
98121 }
99122
100123 /// Read a POD field out of this object.
@@ -133,14 +156,17 @@ impl<'a> VMGcObjectDataMut<'a> {
133156 Some ( into) => into,
134157 None => panic ! (
135158 "out of bounds field! field range = {offset:#x}..{end:#x}; object len = {:#x}" ,
136- self . data. len( ) ,
159+ self . data. as_mut ( ) . len( ) ,
137160 ) ,
138161 } ;
139162 val. write_le ( into. try_into ( ) . unwrap ( ) ) ;
140163 }
141164
142165 /// Get a slice of this object's data.
143166 ///
167+ /// Note that GC data is always stored in little-endian order, and this
168+ /// method does not do any conversions to/from host endianness for you.
169+ ///
144170 /// Panics on out-of-bounds accesses.
145171 #[ inline]
146172 pub fn slice ( & self , offset : u32 , len : u32 ) -> & [ u8 ] {
@@ -152,6 +178,9 @@ impl<'a> VMGcObjectDataMut<'a> {
152178
153179 /// Get a mutable slice of this object's data.
154180 ///
181+ /// Note that GC data is always stored in little-endian order, and this
182+ /// method does not do any conversions to/from host endianness for you.
183+ ///
155184 /// Panics on out-of-bounds accesses.
156185 #[ inline]
157186 pub fn slice_mut ( & mut self , offset : u32 , len : u32 ) -> & mut [ u8 ] {
@@ -163,6 +192,9 @@ impl<'a> VMGcObjectDataMut<'a> {
163192
164193 /// Copy the given slice into this object's data at the given offset.
165194 ///
195+ /// Note that GC data is always stored in little-endian order, and this
196+ /// method does not do any conversions to/from host endianness for you.
197+ ///
166198 /// Panics on out-of-bounds accesses.
167199 #[ inline]
168200 pub fn copy_from_slice ( & mut self , offset : u32 , src : & [ u8 ] ) {
0 commit comments