Macro ash::match_in_struct

source ยท
macro_rules! match_in_struct {
    (match $p:ident { $($bind:ident @ $ty:path => $body:block $(,)?)+ $(_ => $any:block $(,)?)? }) => { ... };
}
Expand description

Given an immutable raw pointer to a type with an s_type member such as vk::BaseInStructure, match on a set of Vulkan structures. The struct will be rebound to the given variable of the type of the given Vulkan structure.

Note that all match bodies have to be enclosed by curly braces due to macro parsing limitations. It is unfortunately not possible to write x @ ash::vk::SomeStruct => one_line_expression(),.

let info = ash::vk::DeviceCreateInfo::default();
let info: *const ash::vk::BaseInStructure = <*const _>::cast(&info);
unsafe {
    ash::match_in_struct!(match info {
        info @ ash::vk::DeviceQueueCreateInfo => {
            dbg!(&info); // Unreachable
        }
        info @ ash::vk::DeviceCreateInfo => {
            dbg!(&info);
        }
    })
}

See the match_out_struct! documentation for an example with implicit return values.