Struct LibTracked

Source
pub struct LibTracked<TLib> { /* private fields */ }
Expand description

A shared library which which allows a user-provided ref-counting implementation to track its Symbols. The inner library will not be droped until all of teh ref-counts are dropped.

Implementations§

Source§

impl<TLib> LibTracked<TLib>
where TLib: AsRef<LibUnsafe> + Clone + From<LibUnsafe>,

Source

pub unsafe fn new<TPath>(path_to_lib: TPath) -> Result<Self>
where TPath: AsRef<Path>,

Opens a shared library at the specified path. The path is used in conjunction with platform specific shared library search paths to determine which shared library will be opened. Search paths vary across environments and are not discussed in this documentation. The behavior of this function when it is called on the same path multiple times is platform specific. If you wish to obtain multiple copies of a library within the same code base in a platform generic way, you should load the symbol once in a LibTracked like LibArc, or LibRc, and pass around copies of the LibTracked.

§Errors

A LibraryOpen error will be returned as a SharedlibError variant if there is a problem opening the shared library. For instance, this may happen if the shared library is not at the path specified.

§Safety

Opening a shared library may execute code within the shared library. Since it is impossible to guarantee that the code witin the shared library is safe, the call to new is unsafe.

§Examples
type LibRc = LibTracked<Rc<LibUnsafe>>;
let lib = try!(unsafe { LibRc::new("examplelib.dll") });
Source

pub unsafe fn find_data<T, TStr>( &self, symbol: TStr, ) -> Result<DataTracked<T, TLib>>
where TStr: AsRef<str>,

Finds and returns a data symbol within the shared library. By passing in a null terminated string, an extra allocation may be avoided.

§Errors

A LibraryFindSymbol error will be returned as a SharedlibError variant if there is a problem finding the symbol. For instance, this may happen if the shared library does not contain the requested symbol.

§Safety

This function is not type safe so there is no guarntee that T is really the type of the symbol. Using a symbol as a T when the symbol is not really of type T causes undefined behavior.

§Examples

Finding data convieniently:

type DataRc<T> = DataTracked<T, Rc<LibUnsafe>>;
let some_usize: DataRc<usize> = try!(unsafe { lib.find_data("some_usize") });

Finding data with maximum performance:

type DataRc<T> = DataTracked<T, Rc<LibUnsafe>>;
let some_usize: DataRc<usize> = try!(unsafe { lib.find_data("some_usize\0") });
Source

pub unsafe fn find_func<T, TStr>( &self, symbol: TStr, ) -> Result<FuncTracked<T, TLib>>
where T: Copy, TStr: AsRef<str>,

Finds and returns a function symbol within the shared library. By passing in a null terminated string, an extra allocation may be avoided.

§Errors

A LibraryFindSymbol error will be returned as a SharedlibError variant if there is a problem finding the symbol. For instance, this may happen if the shared library does not contain the requested symbol.

§Safety

This function is not type safe so there is no guarntee that T is really the type of the symbol. Using a symbol as a T when the symbol is not really of type T causes undefined behavior.

§Examples

Finding a function convieniently:

type FuncRc<T> = FuncTracked<T, Rc<LibUnsafe>>;
let some_func: FuncRc<fn()> = try!(unsafe { lib.find_func("some_func") });

Finding a function with maximum performance:

type FuncRc<T> = FuncTracked<T, Rc<LibUnsafe>>;
let some_func: FuncRc<fn()> = try!(unsafe { lib.find_func("some_func\0") });

Trait Implementations§

Source§

impl<TLib: Clone> Clone for LibTracked<TLib>

Source§

fn clone(&self) -> LibTracked<TLib>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<TLib: Debug> Debug for LibTracked<TLib>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<TLib> Freeze for LibTracked<TLib>
where TLib: Freeze,

§

impl<TLib> RefUnwindSafe for LibTracked<TLib>
where TLib: RefUnwindSafe,

§

impl<TLib> Send for LibTracked<TLib>
where TLib: Send,

§

impl<TLib> Sync for LibTracked<TLib>
where TLib: Sync,

§

impl<TLib> Unpin for LibTracked<TLib>
where TLib: Unpin,

§

impl<TLib> UnwindSafe for LibTracked<TLib>
where TLib: 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.