enum generation: fill in GuestTypeCopy impl

This commit is contained in:
Pat Hickey
2020-01-22 17:23:29 -08:00
parent aa5c5f7018
commit 97077954f8

View File

@@ -82,12 +82,15 @@ fn define_enum(names: &Names, name: &witx::Id, e: &witx::EnumDatatype) -> TokenS
impl ::memory::GuestTypeCopy for #ident { impl ::memory::GuestTypeCopy for #ident {
fn read_val(src: ::memory::GuestPtr<#ident>) -> Result<#ident, ::memory::GuestValueError> { fn read_val(src: ::memory::GuestPtr<#ident>) -> Result<#ident, ::memory::GuestValueError> {
// Get the pointer to memory, cast it to *const #repr, read_unaligned, then use the tryinto use ::std::convert::TryInto;
unimplemented!() let val = unsafe { ::std::ptr::read_unaligned(src.ptr() as *const #repr) };
val.try_into()
} }
fn write_val(val: #ident, dest: ::memory::GuestPtrMut<#ident>) { fn write_val(val: #ident, dest: ::memory::GuestPtrMut<#ident>) {
// use the into<#repr>, get pointer to memory, write_unaligned let val: #repr = val.into();
unimplemented!() unsafe {
::std::ptr::write_unaligned(dest.ptr_mut() as *mut #repr, val)
};
} }
} }
)); ));