From d667e583583e61e60dcc999e2f0cdb7e757a1a07 Mon Sep 17 00:00:00 2001 From: Maik Klein Date: Sat, 9 Mar 2019 17:33:42 +0100 Subject: [PATCH] Add example --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.md b/README.md index 586cd93..4daa8d2 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,23 @@ Builders implement `Deref` targeting their corresponding Vulkan struct, so refer to Vulkan functions. This is encouraged as doing so allows Rust to check the lifetimes of captured objects are valid, whereas calling `build` discards lifetime information, making inadvertent use-after-free errors more likely. +### Pointer chains + +```Rust +let mut variable_pointers = vk::PhysicalDeviceVariablePointerFeatures::builder(); +let mut corner = + vk::PhysicalDeviceCornerSampledImageFeaturesNV::builder(); +; +let mut device_create_info = vk::DeviceCreateInfo::builder() + .push_next(&mut corner) + .push_next(&mut variable_pointers); +``` + +Pointer chains in builders differ from raw Vulkan. Instead of chaining every struct manually, you instead use `.push_next` on the struct that you are going to pass into the function. Those structs then get *pepended* into the chain. + +`push_next` is also type checked, you can only add valid structs to the chain. Both the structs and the builders can be passed into `push_next`. Only builders for structs that can be passed into functions will implement a `push_next`. + + ### Flags and constants as associated constants ```Rust