Container

Struct Container 

Source
pub struct Container<T>
where T: SymBorApi<'static>,
{ /* private fields */ }
Expand description

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§

Source§

impl<T> Container<T>
where T: SymBorApi<'static>,

Source

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

Open dynamic link library and load symbols.

Source

pub unsafe fn load_self() -> Result<Self, Error>

Load all symbols from the program itself.

This allows a shared library to load symbols of the program it was loaded into.

Trait Implementations§

Source§

impl<T> DerefMut for Container<T>
where T: SymBorApi<'static>,

Source§

fn deref_mut(&mut self) -> &mut T

Mutably dereferences the value.
Source§

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

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &T

Dereferences the value.

Auto Trait Implementations§

§

impl<T> Freeze for Container<T>
where T: Freeze,

§

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

§

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

§

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

§

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

§

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

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.