Attribute Macro auto_instanceinfo_impl

Source
#[auto_instanceinfo_impl]
Expand description

Derive the implementation of the vulkan_layer::InstanceInfo trait from the implementation of the vulkan_layer::InstanceHooks.

This attribute macro should be used over an implementation item of the vulkan_layer::InstanceHooks trait, and will implement the vulkan_layer::InstanceInfo trait for the type:

  • InstanceInfo::hooked_commands returns a list of the overridden methods that appear in the implementation item.
  • InstanceInfo::HooksType and InstanceInfo::HooksRefType are defined as Self and &Self.
  • InstanceInfo::hooks returns self.

ยงExamples

use ash::vk;
use std::mem::MaybeUninit;
use vulkan_layer::{
    auto_instanceinfo_impl, InstanceHooks, InstanceInfo, LayerResult, LayerVulkanCommand,
};

#[derive(Default)]
struct MyInstanceHooks;

#[auto_instanceinfo_impl]
impl InstanceHooks for MyInstanceHooks {
    fn get_physical_device_features(
        &self,
        _physical_device: vk::PhysicalDevice,
        _p_features: &mut MaybeUninit<vk::PhysicalDeviceFeatures>,
    ) -> LayerResult<()> {
        LayerResult::Unhandled
    }
}

let my_instance_hooks: MyInstanceHooks = Default::default();
assert!(std::ptr::eq(my_instance_hooks.hooks(), &my_instance_hooks));
assert_eq!(
    MyInstanceHooks::hooked_commands(),
    [LayerVulkanCommand::GetPhysicalDeviceFeatures]
);