Struct dlopen::symbor::Container
[−]
[src]
pub struct Container<T> where
T: SymBorApi<'static>, { /* fields omitted */ }
Container for both dynamic link library handle and its API.
This structure solves an important issue: object oriented programming where the given
structure has two objects and one of the objects has a reference to the second one.
Normally you can't put Library
and a structure that implements SymBorApi
into one structure.
This structure allows you to do it.
Example
#[macro_use] extern crate dlopen_derive; extern crate dlopen; use dlopen::symbor::{Library, Symbol, Ref, PtrOrNull, SymBorApi, Container}; #[derive(SymBorApi)] struct ExampleApi<'a> { pub fun: Symbol<'a, unsafe extern "C" fn(i32) -> i32>, pub glob_i32: Ref<'a, i32>, pub maybe_c_str: PtrOrNull<'a, u8>, } fn main(){ let cont: Container<ExampleApi> = unsafe{Container::load("libexample.so")} .expect("Could not load library or symbols"); println!("fun(4)={}", unsafe{(cont.fun)(4)}); println!("glob_i32={}", *cont.glob_i32); println!("The pointer is null={}", cont.maybe_c_str.is_null()); }
Methods
impl<T> Container<T> where
T: SymBorApi<'static>,
[src]
T: SymBorApi<'static>,
unsafe fn load<S>(name: S) -> Result<Self, Error> where
S: AsRef<OsStr>,
[src]
S: AsRef<OsStr>,
Open dynamic link library and load symbols.
Trait Implementations
impl<T> Deref for Container<T> where
T: SymBorApi<'static>,
[src]
T: SymBorApi<'static>,
type Target = T
The resulting type after dereferencing.
fn deref(&self) -> &T
[src]
Dereferences the value.
impl<T> DerefMut for Container<T> where
T: SymBorApi<'static>,
[src]
T: SymBorApi<'static>,