Struct dlopen::symbor::Library[][src]

pub struct Library { /* fields omitted */ }

Safe wrapper around dynamic link library handle.

Methods of Library return only types that make the library borrowed. Therefore the problem with dangling symbols is prevented.

Note:: It is recommended that you use certain methods in certain situations:

#Example

extern crate dlopen;
use dlopen::symbor::Library;

fn main(){
    let lib = Library::open("libexample.dylib").unwrap();
    let fun = unsafe{lib.symbol::<unsafe extern "C" fn()>("function")}.unwrap();
    unsafe{fun()};
    let glob_val: &mut u32 = unsafe{lib.reference_mut("glob_val")}.unwrap();
    *glob_val = 42;
    let ptr_or_null = unsafe{lib.ptr_or_null::<()>("void_ptr")}.unwrap();
    println!("Pointer is null: {}", ptr_or_null.is_null());
}

Implementations

impl Library[src]

pub fn open<S>(name: S) -> Result<Library, Error> where
    S: AsRef<OsStr>, 
[src]

Open dynamic link library using provided file name or path.

pub fn open_self() -> Result<Library, Error>[src]

Open the program itself as library.

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

pub unsafe fn symbol<T>(&self, name: &str) -> Result<Symbol<'_, T>, Error>[src]

Obtain a symbol from library.

This method is the most general one and allows obtaining basically everything assuming that the value of the given symbol cannot be null (use ptr_or_null() for this case). However the reference() and reference_mut() methods return a native reference and they are more programmer friendly when you try accessing statically allocated data in the library.

pub unsafe fn symbol_cstr<T>(&self, name: &CStr) -> Result<Symbol<'_, T>, Error>[src]

Equivalent of the symbol() method but takes CStr as a argument.

pub unsafe fn ptr_or_null<T>(
    &self,
    name: &str
) -> Result<PtrOrNull<'_, T>, Error>
[src]

Obtain a const pointer from library.

Note: This method is only recommended for data that can’t be accessed as a reference and that can have a null pointer value (so not in 99% of cases).

pub unsafe fn ptr_or_null_cstr<T>(
    &self,
    name: &CStr
) -> Result<PtrOrNull<'_, T>, Error>
[src]

Equivalent of the pointer() method but takes CStr as a argument.

pub unsafe fn ptr_or_null_mut<T>(
    &self,
    name: &str
) -> Result<PtrOrNullMut<'_, T>, Error>
[src]

Obtain a mutable pointer from library.

Note: This method is only recommended for data that can’t be accessed as a reference and that can have a null pointer value (so not in 99% of cases).

pub unsafe fn ptr_or_null_mut_cstr<T>(
    &self,
    name: &CStr
) -> Result<PtrOrNullMut<'_, T>, Error>
[src]

Equivalent of the pointer_mut() method but takes CStr as a argument.

pub unsafe fn reference<T>(&self, name: &str) -> Result<&T, Error>[src]

Obtain const reference to statically allocated data in the library.

pub unsafe fn reference_cstr<T>(&self, name: &CStr) -> Result<&T, Error>[src]

Equivalent of the reference() method but takes CStr as a argument.

pub unsafe fn reference_mut<T>(&self, name: &str) -> Result<&mut T, Error>[src]

Obtain mutable reference to statically allocated data in the library.

pub unsafe fn reference_mut_cstr<T>(&self, name: &CStr) -> Result<&mut T, Error>[src]

Equivalent of the reference_mut() method but takes CStr as a argument.

Trait Implementations

impl Send for Library[src]

impl Sync for Library[src]

Auto Trait Implementations

impl RefUnwindSafe for Library

impl Unpin for Library

impl UnwindSafe for Library

Blanket Implementations

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

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

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

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.