pub trait LibraryLoaderAPI<'a> {
type InternalLoader;
// Required methods
fn to_interface(&self) -> NonNullConst<LibraryLoaderInterface>;
unsafe fn from_interface(
handler: NonNullConst<LibraryLoaderInterface>,
) -> Self;
unsafe fn from_void_ptr(handler: NonNullConst<c_void>) -> Self;
unsafe fn load(
&mut self,
path: &impl AsRef<Path>,
) -> Result<InternalLibrary<Owned>, Error>;
unsafe fn unload(
&mut self,
internal: InternalLibrary<Owned>,
) -> Result<(), Error>;
unsafe fn get_data_symbol<O, U>(
&self,
internal: &InternalLibrary<O>,
symbol: &impl AsRef<CStr>,
caster: impl FnOnce(NonNullConst<c_void>) -> &'a U,
) -> Result<Symbol<'a, &'a U>, Error>
where O: ImmutableAccessIdentifier;
unsafe fn get_function_symbol<O, U>(
&self,
internal: &InternalLibrary<O>,
symbol: &impl AsRef<CStr>,
caster: impl FnOnce(CBaseFn) -> U,
) -> Result<Symbol<'a, U>, Error>
where O: ImmutableAccessIdentifier;
unsafe fn get_internal_interface(&self) -> Self::InternalLoader;
}
Expand description
The API of a library loader.
Required Associated Types§
Sourcetype InternalLoader
type InternalLoader
Type of the internal loader.
Required Methods§
Sourcefn to_interface(&self) -> NonNullConst<LibraryLoaderInterface>
fn to_interface(&self) -> NonNullConst<LibraryLoaderInterface>
Fetches a pointer that can be used with the interface.
Sourceunsafe fn from_interface(handler: NonNullConst<LibraryLoaderInterface>) -> Self
unsafe fn from_interface(handler: NonNullConst<LibraryLoaderInterface>) -> Self
Sourceunsafe fn from_void_ptr(handler: NonNullConst<c_void>) -> Self
unsafe fn from_void_ptr(handler: NonNullConst<c_void>) -> Self
Sourceunsafe fn load(
&mut self,
path: &impl AsRef<Path>,
) -> Result<InternalLibrary<Owned>, Error>
unsafe fn load( &mut self, path: &impl AsRef<Path>, ) -> Result<InternalLibrary<Owned>, Error>
Loads a library. The resulting handle is unique.
§Failure
The function fails if loader
or path
is invalid or
the type of the library can not be loaded with the loader.
§Return
Handle on success, error otherwise.
§Safety
The function crosses the ffi boundary. Direct usage of a LibraryLoaderAPI may break some invariants of the library api, if not handled with care.
Sourceunsafe fn unload(
&mut self,
internal: InternalLibrary<Owned>,
) -> Result<(), Error>
unsafe fn unload( &mut self, internal: InternalLibrary<Owned>, ) -> Result<(), Error>
Unloads a library.
§Failure
The function fails if internal
is invalid.
§Return
Error on failure.
§Safety
The function crosses the ffi boundary. Direct usage of a LibraryLoaderAPI may break some invariants of the library api, if not handled with care.
Sourceunsafe fn get_data_symbol<O, U>(
&self,
internal: &InternalLibrary<O>,
symbol: &impl AsRef<CStr>,
caster: impl FnOnce(NonNullConst<c_void>) -> &'a U,
) -> Result<Symbol<'a, &'a U>, Error>where
O: ImmutableAccessIdentifier,
unsafe fn get_data_symbol<O, U>(
&self,
internal: &InternalLibrary<O>,
symbol: &impl AsRef<CStr>,
caster: impl FnOnce(NonNullConst<c_void>) -> &'a U,
) -> Result<Symbol<'a, &'a U>, Error>where
O: ImmutableAccessIdentifier,
Fetches a data symbol from a library.
§Failure
The function fails if internal
is invalid or library does not contain symbol
.
§Note
Some platforms may differentiate between a function-pointer
and a data-pointer
.
See LibraryLoaderAPI::get_function_symbol() for fetching a function.
§Return
Symbol on success, error otherwise.
§Safety
The function crosses the ffi boundary. Direct usage of a LibraryLoaderAPI may break some invariants of the library api, if not handled with care.
Sourceunsafe fn get_function_symbol<O, U>(
&self,
internal: &InternalLibrary<O>,
symbol: &impl AsRef<CStr>,
caster: impl FnOnce(CBaseFn) -> U,
) -> Result<Symbol<'a, U>, Error>where
O: ImmutableAccessIdentifier,
unsafe fn get_function_symbol<O, U>(
&self,
internal: &InternalLibrary<O>,
symbol: &impl AsRef<CStr>,
caster: impl FnOnce(CBaseFn) -> U,
) -> Result<Symbol<'a, U>, Error>where
O: ImmutableAccessIdentifier,
Fetches a function symbol from a library.
§Failure
The function fails if internal
is invalid or library does not contain symbol
.
§Note
Some platforms may differentiate between a function-pointer
and a data-pointer
.
See LibraryLoaderAPI::get_data_symbol() for fetching some data.
§Return
Symbol on success, error otherwise.
§Safety
The function crosses the ffi boundary. Direct usage of a LibraryLoaderAPI may break some invariants of the library api, if not handled with care.
Sourceunsafe fn get_internal_interface(&self) -> Self::InternalLoader
unsafe fn get_internal_interface(&self) -> Self::InternalLoader
Fetches a pointer to the internal interface.
§Return
Pointer to the interface.
§Safety
The function crosses the ffi boundary. Direct usage of a LibraryLoaderAPI may break some invariants of the library api, if not handled with care.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.