Struct dlopen::symbor::Container [−][src]
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()); }
Implementations
impl<T> Container<T> where
T: SymBorApi<'static>,
[src]
T: SymBorApi<'static>,
pub unsafe fn load<S>(name: S) -> Result<Self, Error> where
S: AsRef<OsStr>,
[src]
S: AsRef<OsStr>,
Open dynamic link library and load symbols.
pub unsafe fn load_self() -> Result<Self, Error>
[src]
Load all symbols from the program itself.
This allows a shared library to load symbols of the program it was loaded into.
Trait Implementations
impl<T> Deref for Container<T> where
T: SymBorApi<'static>,
[src]
T: SymBorApi<'static>,
impl<T> DerefMut for Container<T> where
T: SymBorApi<'static>,
[src]
T: SymBorApi<'static>,
Auto Trait Implementations
impl<T> RefUnwindSafe for Container<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for Container<T> where
T: Send,
T: Send,
impl<T> Sync for Container<T> where
T: Sync,
T: Sync,
impl<T> Unpin for Container<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for Container<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,