diff --git a/src/appkit.rs b/src/appkit.rs index 89429d9..eeae971 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -8,12 +8,21 @@ use std::ptr::NonNull; use crate::Layer; +/// Get or create a new [`Layer`] associated with the given +/// [`AppKitWindowHandle`]. /// +/// # Safety +/// +/// The handle must be valid. pub unsafe fn metal_layer_from_handle(handle: AppKitWindowHandle) -> Layer { unsafe { metal_layer_from_ns_view(handle.ns_view) } } +/// Get or create a new [`Layer`] associated with the given `NSView`. +/// +/// # Safety /// +/// The view must be a valid instance of `NSView`. pub unsafe fn metal_layer_from_ns_view(view: NonNull) -> Layer { // SAFETY: Caller ensures that the view is valid. let obj = unsafe { view.cast::().as_ref() }; diff --git a/src/uikit.rs b/src/uikit.rs index 2bc4bf8..b48bd43 100644 --- a/src/uikit.rs +++ b/src/uikit.rs @@ -5,7 +5,12 @@ use objc2_quartz_core::CAMetalLayer; use raw_window_handle::UiKitWindowHandle; use std::{ffi::c_void, ptr::NonNull}; +/// Get or create a new [`Layer`] associated with the given +/// [`UiKitWindowHandle`]. /// +/// # Safety +/// +/// The handle must be valid. pub unsafe fn metal_layer_from_handle(handle: UiKitWindowHandle) -> Layer { if let Some(_ui_view_controller) = handle.ui_view_controller { // TODO: ui_view_controller support @@ -13,7 +18,11 @@ pub unsafe fn metal_layer_from_handle(handle: UiKitWindowHandle) -> Layer { unsafe { metal_layer_from_ui_view(handle.ui_view) } } +/// Get or create a new [`Layer`] associated with the given `UIView`. +/// +/// # Safety /// +/// The view must be a valid instance of `UIView`. pub unsafe fn metal_layer_from_ui_view(view: NonNull) -> Layer { // SAFETY: Caller ensures that the view is a `UIView`. let view = unsafe { view.cast::().as_ref() };