diff options
| author | mo khan <mo@mokhan.ca> | 2025-07-02 18:36:06 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-07-02 18:36:06 -0600 |
| commit | 8cdfa445d6629ffef4cb84967ff7017654045bc2 (patch) | |
| tree | 22f0b0907c024c78d26a731e2e1f5219407d8102 /vendor/windows-core/src/weak.rs | |
| parent | 4351c74c7c5f97156bc94d3a8549b9940ac80e3f (diff) | |
chore: add vendor directory
Diffstat (limited to 'vendor/windows-core/src/weak.rs')
| -rw-r--r-- | vendor/windows-core/src/weak.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/vendor/windows-core/src/weak.rs b/vendor/windows-core/src/weak.rs new file mode 100644 index 00000000..f89a2315 --- /dev/null +++ b/vendor/windows-core/src/weak.rs @@ -0,0 +1,28 @@ +use super::*; +use core::marker::PhantomData; + +/// `Weak` holds a non-owning reference to an object. +#[derive(Clone, PartialEq, Eq, Default)] +pub struct Weak<I: Interface>(Option<imp::IWeakReference>, PhantomData<I>); + +impl<I: Interface> Weak<I> { + /// Creates a new `Weak` object without any backing object. + pub const fn new() -> Self { + Self(None, PhantomData) + } + + /// Attempts to upgrade the weak reference to a strong reference. + pub fn upgrade(&self) -> Option<I> { + self.0 + .as_ref() + .and_then(|inner| unsafe { inner.Resolve().ok() }) + } + + pub(crate) fn downgrade(source: &imp::IWeakReferenceSource) -> Result<Self> { + let reference = unsafe { source.GetWeakReference().ok() }; + Ok(Self(reference, PhantomData)) + } +} + +unsafe impl<I: Interface> Send for Weak<I> {} +unsafe impl<I: Interface> Sync for Weak<I> {} |
