Struct raw_window_handle::AppKitWindowHandle
source · #[non_exhaustive]pub struct AppKitWindowHandle {
pub ns_view: NonNull<c_void>,
}
Expand description
Raw window handle for AppKit.
Note that NSView
can only be accessed from the main thread of the
application. This struct is !Send
and !Sync
to help with ensuring
that.
§Example
Getting the view from a WindowHandle
.
#![cfg(target_os = "macos")]
use objc2_app_kit::NSView;
use objc2_foundation::is_main_thread;
use objc2::rc::Id;
use raw_window_handle::{WindowHandle, RawWindowHandle};
let handle: WindowHandle<'_>; // Get the window handle from somewhere else
match handle.as_raw() {
RawWindowHandle::AppKit(handle) => {
assert!(is_main_thread(), "can only access AppKit handles on the main thread");
let ns_view = handle.ns_view.as_ptr();
// SAFETY: The pointer came from `WindowHandle`, which ensures
// that the `AppKitWindowHandle` contains a valid pointer to an
// `NSView`.
// Unwrap is fine, since the pointer came from `NonNull`.
let ns_view: Id<NSView> = unsafe { Id::retain(ns_view.cast()) }.unwrap();
// Do something with the NSView here, like getting the `NSWindow`
let ns_window = ns_view.window().expect("view was not installed in a window");
}
handle => unreachable!("unknown handle {handle:?} for platform"),
}
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional
Struct { .. }
syntax; cannot be matched against without a wildcard ..
; and struct update syntax will not work.ns_view: NonNull<c_void>
A pointer to an NSView
object.
Implementations§
Trait Implementations§
source§impl Clone for AppKitWindowHandle
impl Clone for AppKitWindowHandle
source§fn clone(&self) -> AppKitWindowHandle
fn clone(&self) -> AppKitWindowHandle
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for AppKitWindowHandle
impl Debug for AppKitWindowHandle
source§impl From<AppKitWindowHandle> for RawWindowHandle
impl From<AppKitWindowHandle> for RawWindowHandle
source§fn from(value: AppKitWindowHandle) -> Self
fn from(value: AppKitWindowHandle) -> Self
Converts to this type from the input type.
source§impl Hash for AppKitWindowHandle
impl Hash for AppKitWindowHandle
source§impl PartialEq for AppKitWindowHandle
impl PartialEq for AppKitWindowHandle
impl Copy for AppKitWindowHandle
impl Eq for AppKitWindowHandle
impl StructuralPartialEq for AppKitWindowHandle
Auto Trait Implementations§
impl Freeze for AppKitWindowHandle
impl RefUnwindSafe for AppKitWindowHandle
impl !Send for AppKitWindowHandle
impl !Sync for AppKitWindowHandle
impl Unpin for AppKitWindowHandle
impl UnwindSafe for AppKitWindowHandle
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)