pub unsafe trait Element {
// Required method
unsafe fn point_from(ptr: NonNull<u8>) -> NonNull<Self>;
// Provided methods
unsafe fn point_from_align4(ptr: NonNull<u32>) -> NonNull<Self> { ... }
unsafe fn borrow_unchecked<'dat>(ptr: NonNull<u8>) -> &'dat Self { ... }
}Expand description
Required Methods§
unsafe fn point_from(ptr: NonNull<u8>) -> NonNull<Self>
Provided Methods§
Sourceunsafe fn point_from_align4(ptr: NonNull<u32>) -> NonNull<Self>
unsafe fn point_from_align4(ptr: NonNull<u32>) -> NonNull<Self>
Cast a pointer to aligned varlena headers to this type
This version allows you to assume the pointer is aligned to, and readable for, 4 bytes.
This optimization is not required. When in doubt, avoid implementing it, and rely on your
point_from implementation alone.
§Safety
- This must be correctly invoked for the pointee type, as it may deref.
- This must be 4-byte aligned!
Sourceunsafe fn borrow_unchecked<'dat>(ptr: NonNull<u8>) -> &'dat Self
unsafe fn borrow_unchecked<'dat>(ptr: NonNull<u8>) -> &'dat Self
Optimization for borrowing the referent
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".