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§
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more