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 UTypeIds to check compatibility of trait objects
from different dynamic libraries,
because UTypeIds 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 TypeLayouts 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): Ifselfdoesn’t need to be unified across all dynamic libraries, or the representative version doesn’t need to be updated. -
ROk(RSome(_)): Ifselfneeds to be unified across all dynamic libraries, returning the combinedselfandother. -
RErr(_): If there was a problem unifyingselfandother.
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.