Skip to main content

ResourceRep

Trait ResourceRep 

Source
pub unsafe trait ResourceRep<T> {
    // Required methods
    fn rep_new(inner: T) -> Self;
    unsafe fn rep_as_ref<'a>(ptr: *const Self) -> &'a T;
    unsafe fn rep_as_mut<'a>(ptr: *mut Self) -> &'a mut T;
    unsafe fn rep_take<'a>(ptr: *mut Self) -> T;
}
Expand description

A trait used to define how to access the underlying data T from an in-memory representation.

This is used as a bound on the Resource::Rep associated type which is in turn used to access data within a resources.

Required Methods§

Source

fn rep_new(inner: T) -> Self

Creates a new instance of Self which wraps the provided data.

Source

unsafe fn rep_as_ref<'a>(ptr: *const Self) -> &'a T

Acquires &T from a raw pointer to Self.

Source

unsafe fn rep_as_mut<'a>(ptr: *mut Self) -> &'a mut T

Acquires &mut T from a raw pointer to Self.

Source

unsafe fn rep_take<'a>(ptr: *mut Self) -> T

Takes the value out of Self at the provided pointer.

Note that ptr will later be deallocated meaning that it must not run the destructor of T after this method is called. This is guaranteed to be called at most once, however. Additionally after calling this method it’s guaranteed that the rep_as_* method above will not be called.

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<T> ResourceRep<T> for Option<T>

Source§

fn rep_new(inner: T) -> Option<T>

Source§

unsafe fn rep_as_ref<'a>(ptr: *const Option<T>) -> &'a T

Source§

unsafe fn rep_as_mut<'a>(ptr: *mut Option<T>) -> &'a mut T

Source§

unsafe fn rep_take(ptr: *mut Option<T>) -> T

Implementors§