diff --git a/ash/Cargo.toml b/ash/Cargo.toml index 76d33ef..30a53f2 100644 --- a/ash/Cargo.toml +++ b/ash/Cargo.toml @@ -11,7 +11,7 @@ documentation = "https://docs.rs/ash" edition = "2018" [dependencies] -libloading = "0.5.2" +libloading = "0.6.1" [features] default = [] diff --git a/ash/src/entry.rs b/ash/src/entry.rs index 006b1c0..1f55780 100644 --- a/ash/src/entry.rs +++ b/ash/src/entry.rs @@ -5,7 +5,6 @@ use crate::RawPtr; use libloading::Library; use std::error::Error; use std::fmt; -use std::io; use std::mem; use std::os::raw::c_char; use std::os::raw::c_void; @@ -41,19 +40,19 @@ pub struct EntryCustom { } #[derive(Debug)] -pub enum LoadingError { - LibraryLoadError(io::Error), -} +pub struct LoadingError(libloading::Error); impl fmt::Display for LoadingError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match self { - LoadingError::LibraryLoadError(e) => write!(f, "{}", e), - } + fmt::Display::fmt(&self.0, f) } } -impl Error for LoadingError {} +impl Error for LoadingError { + fn source(&self) -> Option<&(dyn Error + 'static)> { + Error::source(&self.0) + } +} #[derive(Clone, Debug)] pub enum InstanceError { @@ -225,29 +224,24 @@ impl EntryCustom> { /// # Ok(()) } /// ``` pub fn new() -> Result { - Self::new_custom( - || { - Library::new(&LIB_PATH) - .map_err(LoadingError::LibraryLoadError) - .map(Arc::new) - }, - |vk_lib, name| unsafe { - vk_lib - .get(name.to_bytes_with_nul()) - .map(|symbol| *symbol) - .unwrap_or(ptr::null_mut()) - }, - ) + let lib = Library::new(&LIB_PATH) + .map_err(LoadingError) + .map(Arc::new)?; + + Ok(Self::new_custom(lib, |vk_lib, name| unsafe { + vk_lib + .get(name.to_bytes_with_nul()) + .map(|symbol| *symbol) + .unwrap_or(ptr::null_mut()) + })) } } impl EntryCustom { - pub fn new_custom(open: Open, mut load: Load) -> Result + pub fn new_custom(mut lib: L, mut load: Load) -> Self where - Open: FnOnce() -> Result, Load: FnMut(&mut L, &::std::ffi::CStr) -> *const c_void, { - let mut lib = open()?; let static_fn = vk::StaticFn::load(|name| load(&mut lib, name)); let entry_fn_1_0 = vk::EntryFnV1_0::load(|name| unsafe { @@ -262,13 +256,13 @@ impl EntryCustom { mem::transmute(static_fn.get_instance_proc_addr(vk::Instance::null(), name.as_ptr())) }); - Ok(EntryCustom { + EntryCustom { static_fn, entry_fn_1_0, entry_fn_1_1, entry_fn_1_2, lib, - }) + } } #[doc = ""]