Debian Codegraph @

third_party/rust/windows-core/src/out_ref.rs

raw
1 use 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)]
7 pub struct OutRef<'a, T: Type<T>>(*mut T::Abi, core::marker::PhantomData<&'a T>);
8
9 impl<'a, T: Type<T>> OutRef<'a, 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(imp::E_POINTER))
19 } else {
20 unsafe { *self.0 = core::mem::transmute_copy(&value) }
21 core::mem::forget(value);
22 Ok(())
23 }
24 }
25 }