diff --git a/Changelog.md b/Changelog.md index 8a2214984..629346349 100644 --- a/Changelog.md +++ b/Changelog.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- Added `Handle::is_null` to allow checking if a handle is a null handle (#694) - Update Vulkan-Headers to 1.3.238 (#688) ### Removed diff --git a/ash/src/vk.rs b/ash/src/vk.rs index 02a5e9c62..09b483ff7 100644 --- a/ash/src/vk.rs +++ b/ash/src/vk.rs @@ -49,4 +49,17 @@ pub trait Handle { const TYPE: ObjectType; fn as_raw(self) -> u64; fn from_raw(_: u64) -> Self; + + /// Returns whether the handle is a null handle. + /// + /// # Examples + /// Basic usage + /// + /// ``` + /// use ash::vk::{Handle, Instance}; + /// + /// let instance = Instance::null(); + /// assert!(instance.is_null()); + /// ``` + fn is_null(&self) -> bool; } diff --git a/ash/src/vk/macros.rs b/ash/src/vk/macros.rs index e986be312..601f6e714 100644 --- a/ash/src/vk/macros.rs +++ b/ash/src/vk/macros.rs @@ -99,6 +99,9 @@ macro_rules! handle_nondispatchable { fn from_raw(x: u64) -> Self { Self(x) } + fn is_null(&self) -> bool { + self.0 == 0 + } } impl $name { pub const fn null() -> Self { @@ -140,6 +143,9 @@ macro_rules! define_handle { fn from_raw(x: u64) -> Self { Self(x as _) } + fn is_null(&self) -> bool { + self.0.is_null() + } } unsafe impl Send for $name {} unsafe impl Sync for $name {}