pub struct ExternalPointer<E: Externalizable> { /* private fields */ }
Expand description

A strongly-typed external pointer. As this is a shared pointer, it only provides immutable references to the underlying data. To allow for interior mutation, use an interior-mutable container such as [RefCell].

Implementations§

source§

impl<E: Externalizable> ExternalPointer<E>

source

pub fn new(external: E) -> Self

source

pub fn into_raw(self) -> *const c_void

source

pub fn from_raw(ptr: *const c_void) -> Self

Create an ExternalPointer from a raw pointer. This does not validate the pointer at all.

source

pub unsafe fn unsafely_deref(&self) -> &E

Unsafely retrieves the underlying object from this pointer after validating it.

§Safety

This method is inherently unsafe because we cannot know if the underlying memory has been deallocated at some point.

The lifetime of the return value is tied to the pointer itself, however you must take care not to use methods that mutate the underlying pointer such as unsafely_take while this reference is alive.

source

pub unsafe fn unsafely_take(self) -> E

Unsafely takes the object from this external.

§Safety

This method is inherently unsafe because we cannot know if the underlying memory has been deallocated at some point.

You must ensure that no other references to this object are alive at the time you call this method.

Auto Trait Implementations§

§

impl<E> RefUnwindSafe for ExternalPointer<E>
where E: RefUnwindSafe,

§

impl<E> !Send for ExternalPointer<E>

§

impl<E> !Sync for ExternalPointer<E>

§

impl<E> Unpin for ExternalPointer<E>
where E: Unpin,

§

impl<E> UnwindSafe for ExternalPointer<E>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.