extern crate adapter; extern crate libloading; use adapter::Adapter; use libloading::{Library, Symbol}; pub struct LibloadingAdapter(pub Library); impl LibloadingAdapter { pub fn from_path(path: &str) -> Result { match unsafe { libloading::Library::new(path) } { Ok(library) => Ok(Self(library)), Err(error) => Err(error), } } } impl<'a, Input, Output, Identifier> Adapter<'a, Input, Output, Identifier> for LibloadingAdapter where Identifier: AsRef<[u8]>, { type Error = libloading::Error; fn call(&'a mut self, identifier: Identifier, input: Input) -> Result { // may be a good idea to cache these. let symbol: Symbol Output> = match unsafe { self.0.get(identifier.as_ref()) } { Ok(symbol) => symbol, Err(error) => return Err(error), }; Ok(symbol(input)) } }