Use the vtable crate for the ItemVTable

This commit is contained in:
Olivier Goffart 2020-05-15 13:45:50 +02:00
parent 49fc23224e
commit f74cfe73cd
6 changed files with 99 additions and 113 deletions

View file

@ -1,7 +1,7 @@
use core::ops::{Deref, DerefMut, Drop};
use core::ptr::NonNull;
use core::marker::PhantomData;
pub use vtable_macro::vtable;
pub use vtable_macro::*;
pub unsafe trait VTableMeta {
/// that's the rust trait. (e.g: `Hello`)
@ -189,6 +189,9 @@ impl<'a, T: ?Sized + VTableMeta> VRefMut<'a, T> {
pub fn into_ref(self) -> VRef<'a, T> {
unsafe { VRef::from_inner(VRefMut::inner(&self)) }
}
pub unsafe fn from_raw(vtable: NonNull<T::VTable>, ptr: NonNull<u8>) -> Self {
Self {inner : T::from_raw(vtable, ptr), _phantom: PhantomData }
}
pub fn get_vtable(&self) -> &T::VTable {
unsafe { T::get_vtable(&self.inner) }
}