[][src]Struct dlopen::wrapper::Container

pub struct Container<T> where
    T: WrapperApi
{ /* fields omitted */ }

Container for both a dynamic load library handle and its API.

Keeping both library and its symbols together makes it safe to use it because symbols are released together with the library. Container also doesn't have any external lifetimes - this makes it easy to use Container inside structures.

#Example

#[macro_use]
extern crate dlopen_derive;
extern crate dlopen;
extern crate libc;
use dlopen::wrapper::{Container, WrapperApi};
use libc::{c_char};
use std::ffi::CStr;

#[derive(WrapperApi)]
struct Example<'a> {
    do_something: extern "C" fn(),
    add_one: unsafe extern "C" fn (arg: i32) -> i32,
    global_count: &'a mut u32,
    c_string: * const c_char
}

//wrapper for c_string won't be generated, implement it here
impl<'a> Example<'a> {
    pub fn c_string(&self) -> &CStr {
        unsafe {CStr::from_ptr(self.c_string)}
    }
}

fn main () {
    let mut container: Container<Example> = unsafe { Container::load("libexample.dylib")}.unwrap();
    container.do_something();
    let _result = unsafe { container.add_one(5) };
    *container.global_count_mut() += 1;
    println!("C string: {}", container.c_string().to_str().unwrap())
}

Methods

impl<T> Container<T> where
    T: WrapperApi
[src]

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

Open the library using provided file name or path and load all symbols.

pub unsafe fn load_self() -> Result<Container<T>, 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: WrapperApi
[src]

impl<T> Deref for Container<T> where
    T: WrapperApi
[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]