Trait abi_stable::abi_stability::extra_checks::ExtraChecks
source · pub unsafe trait ExtraChecks:
Clone
+ Display
+ Debug
+ Send
+ Sync
+ 'static {
// Required methods
fn type_layout(&self) -> &'static TypeLayout;
fn check_compatibility(
&self,
layout_containing_self: &'static TypeLayout,
layout_containing_other: &'static TypeLayout,
checker: TypeCheckerMut<'_>,
) -> RResult<(), ExtraChecksError>;
fn nested_type_layouts<'_self>(
&'_self self,
) -> RCowSlice<'_self, &'static TypeLayout>;
// Provided method
fn combine(
&self,
_other: ExtraChecksRef<'_>,
_checker: TypeCheckerMut<'_>,
) -> RResult<ROption<ExtraChecksBox>, ExtraChecksError> { ... }
}
Expand description
Allows defining extra checks for a type.
Look at the module level documentation for more details.
§Safety
The type_layout
method must be defined as <Self as ::abi_stable::StableAbi>::LAYOUT
,
or equivalent.
All of the methods must be deterministic, always returning the same value with the same arguments.
Required Methods§
sourcefn type_layout(&self) -> &'static TypeLayout
fn type_layout(&self) -> &'static TypeLayout
Gets the type layout of Self
(the type that implements ExtraChecks)
This is used to downcast the trait object in
ForExtraChecksImplementor::downcast_*
methods,
by ensuring that its type layout is
compatible with that of another ExtraChecks trait object
It can’t use UTypeId
s to check compatibility of trait objects
from different dynamic libraries,
because UTypeId
s from different dynamic libraries are incompatible.
sourcefn check_compatibility(
&self,
layout_containing_self: &'static TypeLayout,
layout_containing_other: &'static TypeLayout,
checker: TypeCheckerMut<'_>,
) -> RResult<(), ExtraChecksError>
fn check_compatibility( &self, layout_containing_self: &'static TypeLayout, layout_containing_other: &'static TypeLayout, checker: TypeCheckerMut<'_>, ) -> RResult<(), ExtraChecksError>
Checks that self
is compatible another type which implements ExtraChecks.
Calling check_layout_compatibility
from here will immediately return an error,
prefer doing checker.check_compatibility(...)
instead.
§Parameters
layout_containing_self
:
The TypeLayout that contains this ExtraChecks
trait object in the extra_checks field.
layout_containing_other
:
The TypeLayout that contains the other
ExtraChecks
trait object in the extra_checks field,
which self
is compared to.
checker
:
The type checker,which allows this function to check type layouts.
sourcefn nested_type_layouts<'_self>(
&'_self self,
) -> RCowSlice<'_self, &'static TypeLayout>
fn nested_type_layouts<'_self>( &'_self self, ) -> RCowSlice<'_self, &'static TypeLayout>
Returns the TypeLayout
s owned or referenced by self
.
This is necessary for the Debug implementation of TypeLayout
.
Provided Methods§
sourcefn combine(
&self,
_other: ExtraChecksRef<'_>,
_checker: TypeCheckerMut<'_>,
) -> RResult<ROption<ExtraChecksBox>, ExtraChecksError>
fn combine( &self, _other: ExtraChecksRef<'_>, _checker: TypeCheckerMut<'_>, ) -> RResult<ROption<ExtraChecksBox>, ExtraChecksError>
Combines this ExtraChecks trait object with another one.
To guarantee that the extra_checks
associated with a type (inside <TheType as StableAbi>::LAYOUT.extra_cheks
)
has a single representative value across all dynamic libraries,
you must override this method,
and return ROk(RSome(_))
by combining self
and other
in some way.
§Parameters
other
:
The other ExtraChecks trait object that this is combined with..
checker
:
The trait object of the type checker,which allows this function to check type layouts.
§Return value
This returns:
-
ROk(RNone)
: Ifself
doesn’t need to be unified across all dynamic libraries, or the representative version doesn’t need to be updated. -
ROk(RSome(_))
: Ifself
needs to be unified across all dynamic libraries, returning the combinedself
andother
. -
RErr(_)
: If there was a problem unifyingself
andother
.