[][src]Struct dlopen::symbor::Container

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]

pub unsafe fn load<S>(name: S) -> Result<Self, Error> where
    S: AsRef<OsStr>, 
[src]

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> DerefMut for Container<T> where
    T: SymBorApi<'static>, 
[src]

impl<T> Deref for Container<T> where
    T: SymBorApi<'static>, 
[src]

type Target = T

The resulting type after dereferencing.

Auto Trait Implementations

impl<T> Sync for Container<T> where
    T: Sync

impl<T> Send for Container<T> where
    T: Send

impl<T> Unpin for Container<T> where
    T: Unpin

impl<T> UnwindSafe for Container<T> where
    T: UnwindSafe

impl<T> RefUnwindSafe for Container<T> where
    T: RefUnwindSafe

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]