Skip to main content

storekit/
window.rs

1use core::ffi::c_void;
2use std::ptr::NonNull;
3
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5/// Wraps a caller-owned `NSWindow *` for `StoreKit` APIs that present UI.
6pub struct NSWindowHandle(NonNull<c_void>);
7
8impl NSWindowHandle {
9    /// Wraps a caller-owned `NSWindow *` for `StoreKit` APIs that require a window.
10    ///
11    /// # Safety
12    ///
13    /// `ptr` must point to a live `NSWindow` for the duration of any `StoreKit` call that
14    /// borrows the returned handle. The handle does not retain the window and must not be
15    /// used after the underlying window has been deallocated.
16    pub unsafe fn from_raw(ptr: *mut c_void) -> Option<Self> {
17        NonNull::new(ptr).map(Self)
18    }
19
20    /// Returns the raw `NSWindow *` passed to `StoreKit`.
21    pub const fn as_raw(&self) -> *mut c_void {
22        self.0.as_ptr()
23    }
24}