use crate::*;
pub unsafe trait Interface: Sized + Abi {
type Vtable;
const IID: Guid;
unsafe fn vtable(&self) -> &Self::Vtable {
self.assume_vtable::<Self>()
}
unsafe fn assume_vtable<T: Interface>(&self) -> &T::Vtable {
let this: RawPtr = std::mem::transmute_copy(self);
&(*(*(this as *mut *mut _) as *mut _))
}
fn cast<T: Interface>(&self) -> Result<T> {
unsafe {
let mut result = None;
(self.assume_vtable::<IUnknown>().0)(
std::mem::transmute_copy(self),
&T::IID,
&mut result as *mut _ as _,
)
.and_some(result)
}
}
}