Trait Content

Source
pub unsafe trait Content {
    type Owned;

    // Required methods
    unsafe fn read<F, E>(size: usize, _: F) -> Result<Self::Owned, E>
       where F: FnOnce(&mut Self) -> Result<(), E>;
    fn get_elements_size() -> usize;
    fn to_void_ptr(&self) -> *const ();
    fn ref_from_ptr<'a>(ptr: *mut (), size: usize) -> Option<*mut Self>;
    fn is_size_suitable(: usize) -> bool;
}
Expand description

Trait for types of data that can be put inside buffers.

Required Associated Types§

Source

type Owned

A type that holds a sized version of the content.

Required Methods§

Source

unsafe fn read<F, E>(size: usize, _: F) -> Result<Self::Owned, E>
where F: FnOnce(&mut Self) -> Result<(), E>,

Prepares an output buffer, then turns this buffer into an Owned. User-provided closure F must only write to and not read from &mut Self.

Source

fn get_elements_size() -> usize

Returns the size of each element.

Source

fn to_void_ptr(&self) -> *const ()

Produces a pointer to the data.

Source

fn ref_from_ptr<'a>(ptr: *mut (), size: usize) -> Option<*mut Self>

Builds a pointer to this type from a raw pointer.

Source

fn is_size_suitable(: usize) -> bool

Returns true if the size is suitable to store a type like this.

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> Content for [T]
where T: Copy,

Source§

type Owned = Vec<T>

Source§

unsafe fn read<F, E>(size: usize, f: F) -> Result<Vec<T>, E>
where F: FnOnce(&mut [T]) -> Result<(), E>,

Source§

fn get_elements_size() -> usize

Source§

fn to_void_ptr(&self) -> *const ()

Source§

fn ref_from_ptr<'a>(ptr: *mut (), size: usize) -> Option<*mut [T]>

Source§

fn is_size_suitable(size: usize) -> bool

Implementors§

Source§

impl<T> Content for T
where T: Copy,

Source§

type Owned = T