[][src]Trait abi_stable::library::RootModule

pub trait RootModule: Sized + StableAbi + PrefixRefTrait + 'static {
    pub const BASE_NAME: &'static str;
    pub const NAME: &'static str;
    pub const VERSION_STRINGS: VersionStrings;
    pub const CONSTANTS: RootModuleConsts<Self>;
    pub const CONSTANTS_NO_ABI_INFO: RootModuleConsts<Self>;

    pub fn root_module_statics() -> &'static RootModuleStatics<Self>;

    pub fn get_module() -> Option<Self> { ... }
pub fn get_raw_library() -> Option<&'static RawLibrary> { ... }
pub fn get_library_path(directory: &Path) -> PathBuf { ... }
pub fn load_module_with<F, E>(f: F) -> Result<Self, E>
    where
        F: FnOnce() -> Result<Self, E>
, { ... }
pub fn load_from(where_: LibraryPath<'_>) -> Result<Self, LibraryError> { ... }
pub fn load_from_directory(where_: &Path) -> Result<Self, LibraryError> { ... }
pub fn load_from_file(path_: &Path) -> Result<Self, LibraryError> { ... }
pub fn initialization(self) -> Result<Self, LibraryError> { ... } }

The root module of a dynamic library, which may contain other modules,function pointers,and static references.

For an example of a type implementing this trait you can look at either the example in the readme for this crate, or the example/example_*_interface crates in this crates' repository .

Associated Constants

pub const BASE_NAME: &'static str[src]

The name of the dynamic library,which is the same on all platforms. This is generally the name of the implementation crate.

pub const NAME: &'static str[src]

The name of the library used in error messages.

pub const VERSION_STRINGS: VersionStrings[src]

The version number of the library that this is a root module of.

Initialize this with package_version_strings!()

pub const CONSTANTS: RootModuleConsts<Self>[src]

All the constants of this trait and supertraits.

It can safely be used as a proxy for the associated constants of this trait.

pub const CONSTANTS_NO_ABI_INFO: RootModuleConsts<Self>[src]

Like Self::CONSTANTS, except without including the type layout constant for the root module.

Loading content...

Required methods

pub fn root_module_statics() -> &'static RootModuleStatics<Self>[src]

Gets the statics for Self.

To define this associated function use: abi_stable::declare_root_module_statics!{TypeOfSelf}. Passing Self instead of TypeOfSelf won't work.

Loading content...

Provided methods

pub fn get_module() -> Option<Self>[src]

Gets the root module,returning None if the module is not yet loaded.

pub fn get_raw_library() -> Option<&'static RawLibrary>[src]

Gets the RawLibrary of the module, returning None if the dynamic library failed to load (it doesn't exist or layout checking failed).

Note that if the root module is initialized using Self::load_module_with, this will return None even though Self::get_module does not.

pub fn get_library_path(directory: &Path) -> PathBuf[src]

Returns the path the library would be loaded from,given a directory(folder).

pub fn load_module_with<F, E>(f: F) -> Result<Self, E> where
    F: FnOnce() -> Result<Self, E>, 
[src]

Loads the root module,with a closure which either returns the root module or an error.

If the root module was already loaded, this will return the already loaded root module, without calling the closure.

pub fn load_from(where_: LibraryPath<'_>) -> Result<Self, LibraryError>[src]

Loads this module from the path specified by where_, first loading the dynamic library if it wasn't already loaded.

Once the root module is loaded, this will return the already loaded root module.

Warning

If this function is called within a dynamic library, it must be called at or after the function that exports its root module is called.

DO NOT call this in the static initializer of a dynamic library, since this library relies on setting up its global state before calling the root module loader.

Errors

This will return these errors:

  • LibraryError::OpenError: If the dynamic library itself could not be loaded.

  • LibraryError::GetSymbolError: If the root module was not exported.

  • LibraryError::InvalidAbiHeader: If the abi_stable version used by the library is not compatible.

  • LibraryError::ParseVersionError: If the version strings in the library can't be parsed as version numbers, this can only happen if the version strings are manually constructed.

  • LibraryError::IncompatibleVersionNumber: If the version number of the library is incompatible.

  • LibraryError::AbiInstability: If the layout of the root module is not the expected one.

  • LibraryError::RootModule : If the root module initializer returned an error or panicked.

pub fn load_from_directory(where_: &Path) -> Result<Self, LibraryError>[src]

Loads this module from the directory specified by where_, first loading the dynamic library if it wasn't already loaded.

Once the root module is loaded, this will return the already loaded root module.

Warnings and Errors are detailed in load_from,

pub fn load_from_file(path_: &Path) -> Result<Self, LibraryError>[src]

Loads this module from the file at path_, first loading the dynamic library if it wasn't already loaded.

Once the root module is loaded, this will return the already loaded root module.

Warnings and Errors are detailed in load_from,

pub fn initialization(self) -> Result<Self, LibraryError>[src]

Defines behavior that happens once the module is loaded.

The default implementation does nothing.

Loading content...

Implementors

impl RootModule for Module_Ref[src]

Loading content...