Struct abi_stable::library::LibHeader
source · #[repr(C)]pub struct LibHeader { /* private fields */ }
Expand description
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§
source§impl LibHeader
impl LibHeader
sourcepub const unsafe fn from_constructor<M>(
constructor: extern "C" fn() -> RootModuleResult,
check_layout: CheckTypeLayout,
) -> Selfwhere
M: RootModule,
pub const unsafe fn from_constructor<M>(
constructor: extern "C" fn() -> RootModuleResult,
check_layout: CheckTypeLayout,
) -> Selfwhere
M: RootModule,
Constructs a LibHeader from the root module loader.
§Safety
The PrefixRef<ErasedPrefix>
returned by the constructor
function
must have been transmuted from a PrefixRef<M>
.
sourcepub fn from_module<M>(value: M) -> Selfwhere
M: RootModule,
pub fn from_module<M>(value: M) -> Selfwhere
M: RootModule,
Constructs a LibHeader from the module.
sourcepub const fn root_mod_consts(&self) -> &RootModuleConsts
pub const fn root_mod_consts(&self) -> &RootModuleConsts
All the important constants of a RootModule
for some erased type.
sourcepub const fn version_strings(&self) -> VersionStrings
pub const fn version_strings(&self) -> VersionStrings
The version string of the library the module is being loaded from.
sourcepub const fn layout(&self) -> Option<&'static TypeLayout>
pub const fn layout(&self) -> Option<&'static TypeLayout>
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.
sourcepub fn init_root_module<M>(&self) -> Result<M, LibraryError>where
M: RootModule,
pub fn init_root_module<M>(&self) -> Result<M, LibraryError>where
M: RootModule,
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.
sourcepub unsafe fn init_root_module_with_unchecked_layout<M>(
&self,
) -> Result<M, LibraryError>where
M: RootModule,
pub unsafe fn init_root_module_with_unchecked_layout<M>(
&self,
) -> Result<M, LibraryError>where
M: RootModule,
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.
sourcepub fn ensure_layout<M>(&self) -> Result<(), LibraryError>where
M: RootModule,
pub fn ensure_layout<M>(&self) -> Result<(), LibraryError>where
M: RootModule,
Checks that the layout of the M
root module 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.
sourcepub fn check_layout<M>(&self) -> Result<M, LibraryError>where
M: RootModule,
pub fn check_layout<M>(&self) -> Result<M, LibraryError>where
M: RootModule,
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.
sourcepub unsafe fn unchecked_layout<M>(&self) -> Result<M, RootModuleError>where
M: PrefixRefTrait,
pub unsafe fn unchecked_layout<M>(&self) -> Result<M, RootModuleError>where
M: PrefixRefTrait,
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§
source§impl GetStaticEquivalent_ for LibHeader
impl GetStaticEquivalent_ for LibHeader
source§type StaticEquivalent = _static_LibHeader
type StaticEquivalent = _static_LibHeader
'static
equivalent of Self
source§impl StableAbi for LibHeader
impl StableAbi for LibHeader
source§type IsNonZeroType = False
type IsNonZeroType = False
source§const LAYOUT: &'static TypeLayout = _
const LAYOUT: &'static TypeLayout = _
source§const ABI_CONSTS: AbiConsts = _
const ABI_CONSTS: AbiConsts = _
const
-equivalents of the associated types.Auto Trait Implementations§
impl !Freeze for LibHeader
impl RefUnwindSafe for LibHeader
impl Send for LibHeader
impl Sync for LibHeader
impl Unpin for LibHeader
impl UnwindSafe for LibHeader
Blanket Implementations§
source§impl<T> AlignerFor<1> for T
impl<T> AlignerFor<1> for T
source§impl<T> AlignerFor<1024> for T
impl<T> AlignerFor<1024> for T
source§type Aligner = AlignTo1024<T>
type Aligner = AlignTo1024<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.source§impl<T> AlignerFor<128> for T
impl<T> AlignerFor<128> for T
source§type Aligner = AlignTo128<T>
type Aligner = AlignTo128<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.source§impl<T> AlignerFor<16> for T
impl<T> AlignerFor<16> for T
source§impl<T> AlignerFor<16384> for T
impl<T> AlignerFor<16384> for T
source§type Aligner = AlignTo16384<T>
type Aligner = AlignTo16384<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.source§impl<T> AlignerFor<2> for T
impl<T> AlignerFor<2> for T
source§impl<T> AlignerFor<2048> for T
impl<T> AlignerFor<2048> for T
source§type Aligner = AlignTo2048<T>
type Aligner = AlignTo2048<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.source§impl<T> AlignerFor<256> for T
impl<T> AlignerFor<256> for T
source§type Aligner = AlignTo256<T>
type Aligner = AlignTo256<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.source§impl<T> AlignerFor<32> for T
impl<T> AlignerFor<32> for T
source§impl<T> AlignerFor<32768> for T
impl<T> AlignerFor<32768> for T
source§type Aligner = AlignTo32768<T>
type Aligner = AlignTo32768<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.source§impl<T> AlignerFor<4> for T
impl<T> AlignerFor<4> for T
source§impl<T> AlignerFor<4096> for T
impl<T> AlignerFor<4096> for T
source§type Aligner = AlignTo4096<T>
type Aligner = AlignTo4096<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.source§impl<T> AlignerFor<512> for T
impl<T> AlignerFor<512> for T
source§type Aligner = AlignTo512<T>
type Aligner = AlignTo512<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.source§impl<T> AlignerFor<64> for T
impl<T> AlignerFor<64> for T
source§impl<T> AlignerFor<8> for T
impl<T> AlignerFor<8> for T
source§impl<T> AlignerFor<8192> for T
impl<T> AlignerFor<8192> for T
source§type Aligner = AlignTo8192<T>
type Aligner = AlignTo8192<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<S> ROExtAcc for S
impl<S> ROExtAcc for S
source§fn f_get<F>(&self, offset: FieldOffset<S, F, Aligned>) -> &F
fn f_get<F>(&self, offset: FieldOffset<S, F, Aligned>) -> &F
offset
. Read moresource§fn f_get_mut<F>(&mut self, offset: FieldOffset<S, F, Aligned>) -> &mut F
fn f_get_mut<F>(&mut self, offset: FieldOffset<S, F, Aligned>) -> &mut F
offset
. Read moresource§fn f_get_ptr<F, A>(&self, offset: FieldOffset<S, F, A>) -> *const F
fn f_get_ptr<F, A>(&self, offset: FieldOffset<S, F, A>) -> *const F
offset
. Read moresource§fn f_get_mut_ptr<F, A>(&mut self, offset: FieldOffset<S, F, A>) -> *mut F
fn f_get_mut_ptr<F, A>(&mut self, offset: FieldOffset<S, F, A>) -> *mut F
offset
. Read moresource§impl<S> ROExtOps<Aligned> for S
impl<S> ROExtOps<Aligned> for S
source§fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Aligned>, value: F) -> F
fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Aligned>, value: F) -> F
offset
) with value
,
returning the previous value of the field. Read moresource§fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Aligned>) -> Fwhere
F: Copy,
fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Aligned>) -> Fwhere
F: Copy,
source§impl<S> ROExtOps<Unaligned> for S
impl<S> ROExtOps<Unaligned> for S
source§fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, value: F) -> F
fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, value: F) -> F
offset
) with value
,
returning the previous value of the field. Read moresource§fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Unaligned>) -> Fwhere
F: Copy,
fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Unaligned>) -> Fwhere
F: Copy,
source§impl<T> SelfOps for Twhere
T: ?Sized,
impl<T> SelfOps for Twhere
T: ?Sized,
source§fn piped<F, U>(self, f: F) -> U
fn piped<F, U>(self, f: F) -> U
source§fn piped_ref<'a, F, U>(&'a self, f: F) -> Uwhere
F: FnOnce(&'a Self) -> U,
fn piped_ref<'a, F, U>(&'a self, f: F) -> Uwhere
F: FnOnce(&'a Self) -> U,
piped
except that the function takes &Self
Useful for functions that take &Self
instead of Self
. Read moresource§fn piped_mut<'a, F, U>(&'a mut self, f: F) -> Uwhere
F: FnOnce(&'a mut Self) -> U,
fn piped_mut<'a, F, U>(&'a mut self, f: F) -> Uwhere
F: FnOnce(&'a mut Self) -> U,
piped
, except that the function takes &mut Self
.
Useful for functions that take &mut Self
instead of Self
.source§fn mutated<F>(self, f: F) -> Self
fn mutated<F>(self, f: F) -> Self
source§fn observe<F>(self, f: F) -> Self
fn observe<F>(self, f: F) -> Self
source§fn as_ref_<T>(&self) -> &T
fn as_ref_<T>(&self) -> &T
AsRef
,
using the turbofish .as_ref_::<_>()
syntax. Read more