pub trait ObjectOrVariantHelper<T, U> {
// Required methods
fn convert_to_dest_type_helper(object: &T) -> Option<&U>;
fn convert_to_dest_type_helper_mut(object: &mut T) -> Option<&mut U>;
}Expand description
This trait is a helper trait for implementing ObjectOrVariant indirectly in child crates.
To implement ObjectOrVariant for type U in a child crate, you need to implement ObjectOrVariantHelper for PhantomData<U>.
This is necessary because Rust does not support impl<T> ForeignTrait<LocalType> for T
But Rust does support impl<T> ForeignTrait<LocalType> for ForeignType<T>
Details can be found in here.
Therefore, we cannot implement ObjectOrVariant directly using impl<U: TraitBound> ObjectOrVariant<LocalType> for U
but we can do impl<U: TraitBound> ObjectOrVariantHelper<LocalType, U> for PhantomData<U>
There is an indirection to get rid of PhantomData<U> because we want to have a clean API for pool methods
where you can pass in U directly instead of PhantomData<U>.
Required Methods§
fn convert_to_dest_type_helper(object: &T) -> Option<&U>
fn convert_to_dest_type_helper_mut(object: &mut T) -> Option<&mut U>
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.