#[doc(hidden)] pub unsafe trait HasField<Field, const VARIANT_ID: i128, const FIELD_ID: i128> {
type Type: ?Sized;
// Required methods
fn only_derive_is_allowed_to_implement_this_trait()
where Self: Sized;
fn project(slf: PtrInner<'_, Self>) -> *mut Self::Type;
}Expand description
Projects a given field from Self.
All implementations of HasField for a particular field f in Self
should use the same Field type; this ensures that Field is inferable
given an explicit VARIANT_ID and FIELD_ID.
§Safety
A field f is HasField for Self if and only if:
- If
Selfis a struct or union type, thenVARIANT_IDisSTRUCT_VARIANT_IDorUNION_VARIANT_IDrespectively; otherwise, ifSelfis an enum type,VARIANT_IDis the numerical index of the enum variant in whichfappears. - If
fhas namen,FIELD_IDiszerocopy::ident_id!(n); otherwise, iffis at indexi,FIELD_IDiszerocopy::ident_id!(i). Fieldis a type with the same visibility asf.Typehas the same type asf.
The caller must not assume that a pointer’s referent being aligned
implies that calling project on that pointer will result in a pointer to
an aligned referent. For example, HasField may be implemented for
#[repr(packed)] structs.
The implementation of project must satisfy its safety post-condition.
Required Associated Types§
Required Methods§
fn only_derive_is_allowed_to_implement_this_trait()where
Self: Sized,
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.