use super::*;
#[repr(transparent)]
pub struct OutRef<'a, T: Type>(*mut T::Abi, core::marker::PhantomData<&'a T>);
impl<T: Type> OutRef<'_, T> {
pub fn is_null(&self) -> bool {
self.0.is_null()
}
pub fn write(self, value: T::Default) -> Result<()> {
if self.0.is_null() {
Err(Error::from_hresult(imp::E_POINTER))
} else {
unsafe { self.0.cast::<T::Default>().write(value) }
Ok(())
}
}
}
impl<'a, T: Type> From<&'a mut T::Default> for OutRef<'a, T>
where
&'a mut T::Default: OutParam<T>,
{
fn from(from: &'a mut T::Default) -> Self {
Self(
unsafe { OutParam::<T>::borrow_mut(&from) }.0,
core::marker::PhantomData,
)
}
}
impl<T: Type> Default for OutRef<'_, T> {
fn default() -> Self {
OutRef(core::ptr::null_mut(), core::marker::PhantomData)
}
}