1use super::*;
2
3/// A borrowed type with the same memory layout as the type itself that can be used to construct ABI-compatible function signatures.
4///
5/// This is a mutable version of [Ref] meant to support out parameters.
6#[repr(transparent)]
7pub struct OutRef<'a, T: Type<T>>(*mut T::Abi, core::marker::PhantomData<&'a T>);
8
9impl<T: Type<T>> OutRef<'_, T> {
10 /// Returns `true` if the argument is null.
11 pub fn is_null(&self) -> bool {
12 self.0.is_null()
13 }
14
15 /// Overwrites a memory location with the given value without reading or dropping the old value.
16 pub fn write(self, value: T::Default) -> Result<()> {
17 if self.0.is_null() {
18 Err(Error::from_hresult(code:imp::E_POINTER))
19 } else {
20 unsafe { *self.0 = core::mem::transmute_copy(&value) }
21 core::mem::forget(value);
22 Ok(())
23 }
24 }
25}
26
27impl<'a, T: Type<T>> From<&'a mut T::Default> for OutRef<'a, T> {
28 fn from(from: &'a mut T::Default) -> Self {
29 unsafe { core::mem::transmute(src:from) }
30 }
31}
32