pub unsafe trait WithUnderlier:
Sized
+ Zeroable
+ Copy
+ Send
+ Sync
+ 'static {
type Underlier: UnderlierType;
// Required methods
fn to_underlier(self) -> Self::Underlier;
fn to_underlier_ref(&self) -> &Self::Underlier;
fn to_underlier_ref_mut(&mut self) -> &mut Self::Underlier;
fn to_underliers_ref(val: &[Self]) -> &[Self::Underlier];
fn to_underliers_ref_mut(val: &mut [Self]) -> &mut [Self::Underlier];
fn from_underlier(val: Self::Underlier) -> Self;
fn from_underlier_ref(val: &Self::Underlier) -> &Self;
fn from_underlier_ref_mut(val: &mut Self::Underlier) -> &mut Self;
fn from_underliers_ref(val: &[Self::Underlier]) -> &[Self];
fn from_underliers_ref_mut(val: &mut [Self::Underlier]) -> &mut [Self];
// Provided method
fn mutate_underlier(
self,
f: impl FnOnce(Self::Underlier) -> Self::Underlier,
) -> Self { ... }
}
Expand description
A type that is transparently backed by an underlier.
This trait is needed to make it possible getting the underlier type from already defined type.
Bidirectional From
trait implementations are not enough, because they do not allow getting underlier type
in a generic code.
§Safety
WithUnderlier
can be implemented for a type only if it’s representation is a transparent Underlier
’s representation.
That’s allows us casting references of type and it’s underlier in both directions.
Required Associated Types§
sourcetype Underlier: UnderlierType
type Underlier: UnderlierType
Underlier primitive type
Required Methods§
sourcefn to_underlier(self) -> Self::Underlier
fn to_underlier(self) -> Self::Underlier
Convert value to underlier.
fn to_underlier_ref(&self) -> &Self::Underlier
fn to_underlier_ref_mut(&mut self) -> &mut Self::Underlier
fn to_underliers_ref(val: &[Self]) -> &[Self::Underlier]
fn to_underliers_ref_mut(val: &mut [Self]) -> &mut [Self::Underlier]
fn from_underlier(val: Self::Underlier) -> Self
fn from_underlier_ref(val: &Self::Underlier) -> &Self
fn from_underlier_ref_mut(val: &mut Self::Underlier) -> &mut Self
fn from_underliers_ref(val: &[Self::Underlier]) -> &[Self]
fn from_underliers_ref_mut(val: &mut [Self::Underlier]) -> &mut [Self]
Provided Methods§
fn mutate_underlier( self, f: impl FnOnce(Self::Underlier) -> Self::Underlier, ) -> Self
Object Safety§
This trait is not object safe.