[][src]Struct abi_stable::library::LibHeader

#[repr(C)]pub struct LibHeader { /* fields omitted */ }

Used to check the layout of modules returned by module-loading functions exported by dynamic libraries.

Module-loading functions are declared with the export_root_module attribute.

Implementations

impl LibHeader[src]

pub const unsafe fn from_constructor<M>(
    constructor: Constructor<RootModuleResult>,
    root_mod_consts: RootModuleConsts<M>
) -> Self
[src]

Constructs a LibHeader from the root module loader.

Safety

The PrefixRef<ErasedPrefix> returned by the function that constructor wraps must be have been transmuted from a PrefixRef<M>.

pub fn from_module<T>(value: T) -> Self where
    T: RootModule
[src]

Constructs a LibHeader from the module.

pub fn root_mod_consts(&self) -> &ErasedRootModuleConsts[src]

All the important constants of a RootModule for some erased type.

pub fn version_strings(&self) -> VersionStrings[src]

The version string of the library the module is being loaded from.

pub fn layout(&self) -> Option<&'static TypeLayout>[src]

Gets the layout of the root module.

This returns a None if the root module layout is not included because the #[unsafe_no_layout_constant] helper attribute was used on the function exporting the root module.

pub fn init_root_module<M>(&self) -> Result<M, LibraryError> where
    M: RootModule
[src]

Checks that the library is compatible,returning the root module on success.

It checks that these are compatible:

  • The version number of the library

  • The layout of the 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 returns these errors:

  • 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 unsafe fn init_root_module_with_unchecked_layout<M>(
    &self
) -> Result<M, LibraryError> where
    M: RootModule
[src]

Checks that the version number of the library is compatible, returning the root module on success.

This function transmutes the root module type, without checking that the layout is compatible first.

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.

Safety

The caller must ensure that M has the expected layout.

Errors

This returns these errors:

  • 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::RootModule : If the root module initializer returned an error or panicked.

pub fn check_layout<M>(&self) -> Result<M, LibraryError> where
    M: RootModule
[src]

Gets the root module,first checking that the layout of the M from the dynamic library is compatible with the expected layout.

Errors

This returns these errors:

  • 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 unsafe fn unchecked_layout<M>(&self) -> Result<M, RootModuleError> where
    M: PrefixRefTrait
[src]

Gets the root module without checking that the layout of M is the expected one. This is effectively a transmute.

This is useful if a user keeps a cache of which dynamic libraries have been checked for layout compatibility.

Safety

The caller must ensure that M has the expected layout.

Errors

This function can return a RootModuleError because the root module failed to initialize.

Trait Implementations

impl GetStaticEquivalent_ for LibHeader[src]

type StaticEquivalent = _static_LibHeader

impl StableAbi for LibHeader[src]

type IsNonZeroType = False

Whether this type has a single invalid bit-pattern. Read more

Auto Trait Implementations

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> GetWithMetadata for T[src]

type ForSelf = WithMetadata_<T, T>

This is always WithMetadata_<Self, Self>

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

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

impl<This> TransmuteElement for This where
    This: ?Sized
[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.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The error type returned when the conversion fails.

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

type Type = T

The same type as Self. Read more