Trait PointerLength

Source
pub unsafe trait PointerLength {
    // Required method
    fn len(ptr: *const Self) -> usize;
}
Expand description

A trait which is only implemented for pointers for which the length of the pointee can be determined without creating a reference to the pointee and without accessing the pointee. This means that the pointer is not dereferenced.

§Example

use deferred_reference::PointerLength;
let array = [0usize; 1024];
assert_eq!(1024, PointerLength::len(core::ptr::addr_of!(array)));

§Safety

This trait is unsafe. The implementor must promise never to access or create a reference to the pointee.

Required Methods§

Source

fn len(ptr: *const Self) -> usize

Obtains the length of the pointee, without creating an intermediate reference.

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.

Implementations on Foreign Types§

Source§

impl<T> PointerLength for [T]

Source§

fn len(ptr: *const Self) -> usize

Source§

impl<T, const N: usize> PointerLength for [T; N]

Source§

fn len(_: *const Self) -> usize

Implementors§