Skip to main content

Loader

Trait Loader 

Source
pub unsafe trait Loader: Send + Sync {
    // Required method
    unsafe fn load(&self, name: &CStr) -> *const c_void;
}
Expand description

Abstraction over loading symbols from the Vulkan shared library.

§Safety

Implementations must return valid function pointers for the requested symbol name, or null if the symbol is not found. Returning a pointer to the wrong function causes undefined behavior.

§Examples

use std::ffi::{CStr, c_void};
use vulkan_rust::Loader;

struct NullLoader;

unsafe impl Loader for NullLoader {
    unsafe fn load(&self, _name: &CStr) -> *const c_void {
        std::ptr::null()
    }
}

let loader = NullLoader;
let ptr = unsafe { loader.load(c"vkCreateInstance") };
assert!(ptr.is_null());

Required Methods§

Source

unsafe fn load(&self, name: &CStr) -> *const c_void

Load a function by name from the Vulkan library.

Returns a raw function pointer, or null if the symbol is not found.

§Safety

The caller must only transmute the returned pointer to a function type matching the Vulkan command identified by name.

Implementors§