Skip to main content

Element

Trait Element 

Source
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

BorrowDatum for array elements

§Safety

As BorrowDatum, due to the blanket implementation.

Required Methods§

Source

unsafe fn point_from(ptr: NonNull<u8>) -> NonNull<Self>

Provided Methods§

Source

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!
Source

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".

Implementations on Foreign Types§

Source§

impl Element for CStr

Source§

unsafe fn point_from(ptr: NonNull<u8>) -> NonNull<Self>

Source§

unsafe fn borrow_unchecked<'dat>(ptr: NonNull<u8>) -> &'dat Self

Source§

impl Element for bool

Source§

unsafe fn point_from(ptr: NonNull<u8>) -> NonNull<Self>

Source§

impl Element for f32

Source§

unsafe fn point_from(ptr: NonNull<u8>) -> NonNull<Self>

Source§

impl Element for f64

Source§

unsafe fn point_from(ptr: NonNull<u8>) -> NonNull<Self>

Source§

impl Element for i8

Source§

unsafe fn point_from(ptr: NonNull<u8>) -> NonNull<Self>

Source§

impl Element for i16

Source§

unsafe fn point_from(ptr: NonNull<u8>) -> NonNull<Self>

Source§

impl Element for i32

Source§

unsafe fn point_from(ptr: NonNull<u8>) -> NonNull<Self>

Source§

impl Element for i64

Source§

unsafe fn point_from(ptr: NonNull<u8>) -> NonNull<Self>

Implementors§