#[derive(Debug)]
pub struct DynLib {
inner: libloading::Library,
}
impl DynLib {
pub unsafe fn new
(filename: P) -> Result
where
P: AsRef,
{
unsafe { libloading::Library::new(filename) }.map(|inner| Self { inner })
}
pub unsafe fn get(
&self,
symbol: &[u8],
) -> Result, crate::DeviceError> {
unsafe { self.inner.get(symbol) }.map_err(|e| match e {
libloading::Error::GetProcAddress { .. } | libloading::Error::GetProcAddressUnknown => {
crate::DeviceError::Unexpected
}
libloading::Error::IncompatibleSize
| libloading::Error::CreateCString { .. }
| libloading::Error::CreateCStringWithTrailing { .. } => crate::hal_internal_error(e),
_ => crate::DeviceError::Unexpected, // could be unreachable!() but we prefer to be more robust
})
}
}