pub unsafe trait UnderlierView:
TransparentWrapper<Self::Underlier>
+ Sized
+ Zeroable
+ Copy
+ Send
+ Sync
+ 'static {
type Underlier: Underlier;
// Provided 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] { ... }
fn mutate_underlier(
self,
f: impl FnOnce(Self::Underlier) -> Self::Underlier,
) -> Self { ... }
}Expand description
A type stored exactly as some underlier, and freely viewable as one.
A binary field element is a bit pattern with arithmetic attached. The bits sit in an underlier, and the element type wraps it to give those bits meaning.
Declaring that wrapper transparent means the two share an address, a size, and a bit pattern:
element [ bits ] <- arithmetic attached
underlier [ bits ] <- same address, same size, nothing to convertSo a value, a reference, or a whole slice can be viewed as the other side for free. Viewing a slice matters most, since it lets bulk code work on plain bits without copying.
The wrapping alone would be expressible with conversions in both directions. What those cannot give is the underlier’s name. Generic code needs that name to state bounds against it. Carrying it as an associated type is what this trait adds.
§Safety
An implementor must have the same representation as the underlier it names. That is what makes casting a reference in either direction sound.
Required Associated Types§
Provided Methods§
Sourcefn to_underlier(self) -> Self::Underlier
fn to_underlier(self) -> Self::Underlier
Views this value as its underlier.
Sourcefn to_underlier_ref(&self) -> &Self::Underlier
fn to_underlier_ref(&self) -> &Self::Underlier
Views a shared reference as one to its underlier.
Sourcefn to_underlier_ref_mut(&mut self) -> &mut Self::Underlier
fn to_underlier_ref_mut(&mut self) -> &mut Self::Underlier
Views a mutable reference as one to its underlier.
Sourcefn to_underliers_ref(val: &[Self]) -> &[Self::Underlier]
fn to_underliers_ref(val: &[Self]) -> &[Self::Underlier]
Views a slice as a slice of underliers, without copying.
Sourcefn to_underliers_ref_mut(val: &mut [Self]) -> &mut [Self::Underlier]
fn to_underliers_ref_mut(val: &mut [Self]) -> &mut [Self::Underlier]
Views a mutable slice as a mutable slice of underliers, without copying.
Sourcefn from_underlier(val: Self::Underlier) -> Self
fn from_underlier(val: Self::Underlier) -> Self
Reads an underlier as this type.
Sourcefn from_underlier_ref(val: &Self::Underlier) -> &Self
fn from_underlier_ref(val: &Self::Underlier) -> &Self
Views a shared reference to an underlier as one to this type.
Sourcefn from_underlier_ref_mut(val: &mut Self::Underlier) -> &mut Self
fn from_underlier_ref_mut(val: &mut Self::Underlier) -> &mut Self
Views a mutable reference to an underlier as one to this type.
Sourcefn from_underliers_ref(val: &[Self::Underlier]) -> &[Self]
fn from_underliers_ref(val: &[Self::Underlier]) -> &[Self]
Views a slice of underliers as a slice of this type, without copying.
Sourcefn from_underliers_ref_mut(val: &mut [Self::Underlier]) -> &mut [Self]
fn from_underliers_ref_mut(val: &mut [Self::Underlier]) -> &mut [Self]
Views a mutable slice of underliers as a mutable slice of this type, without copying.
Sourcefn mutate_underlier(
self,
f: impl FnOnce(Self::Underlier) -> Self::Underlier,
) -> Self
fn mutate_underlier( self, f: impl FnOnce(Self::Underlier) -> Self::Underlier, ) -> Self
Rewrites the bits through a function on the underlier, keeping this type on both ends.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".