add more scary transmutation traits
@@ -492,11 +492,15 @@ pub trait NativeTransmutable<NT: Sized> : Sized {
}
// TODO: this seems to actually copy, which is probably not what we want.
+ // TODO: this should only be possible for transmutable pairs that are
+ // both Copy
fn from_native(nt: NT) -> Self {
unsafe { mem::transmute_copy::<NT, Self>(&nt) }
}
// TODO: this seems to actually copy, which is probably not what we want.
+ // TODO: this should only be possible for transmutable pairs that are
+ // both Copy
fn into_native(self) -> NT {
unsafe { mem::transmute_copy::<Self, NT>(&self) }
}
@@ -523,6 +527,23 @@ impl<NT, ElementT> NativeTransmutableSliceAccess<NT> for [ElementT]
}
}
+impl<NT, ElementT> NativeTransmutable<Option<&[NT]>> for Option<&[ElementT]>
+ where ElementT: NativeTransmutable<NT> {}
+
+pub trait NativeTransmutableOptionSliceAccessMut<NT: Sized> {
+ fn native_mut(&mut self) -> &mut Option<&mut [NT]>;
+}
+
+impl<NT, ElementT> NativeTransmutableOptionSliceAccessMut<NT> for Option<&mut [ElementT]>
+ where ElementT: NativeTransmutable<NT> {
+
+ fn native_mut(&mut self) -> &mut Option<&mut [NT]> {
+ unsafe {
+ mem::transmute::<&mut Option<&mut [ElementT]>, &mut Option<&mut [NT]>>(self)
+ }
+ }
+}
+
//
// Convenience functions to access Option<&[]> as optional ptr (opt_ptr)
// that may be null.
