cooked_waker

Trait ViaRawPointer

Source
pub unsafe trait ViaRawPointer {
    type Target: ?Sized;

    // Required methods
    fn into_raw(self) -> *mut Self::Target;
    unsafe fn from_raw(ptr: *mut Self::Target) -> Self;
}
Expand description

Trait for types that can be converted into raw pointers and back again.

§Safety

  • Implementors must ensure that, for a given object, the pointer remains fixed as long as no mutable operations are performed (that is, calling from_ptr() followed by into_ptr(), with no mutable operations in between, the returned pointer has the same value.)
  • Implementors also must not panic when the interface is used correctly. The Waker constructed by IntoWaker can cause a double drop if either of these functions panic.

In the future, we hope to have a similar trait added to the standard library; see https://github.com/rust-lang/rust/issues/75846 for details.

Required Associated Types§

Required Methods§

Source

fn into_raw(self) -> *mut Self::Target

Convert this object into a raw pointer.

Source

unsafe fn from_raw(ptr: *mut Self::Target) -> Self

Convert a raw pointer back into this object.

§Safety

This method must ONLY be called on a pointer that was received via Self::into_raw, and that pointer must not be used afterwards.

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> ViaRawPointer for Weak<T>

Source§

type Target = T

Source§

fn into_raw(self) -> *mut T

Source§

unsafe fn from_raw(ptr: *mut T) -> Self

Source§

impl<T> ViaRawPointer for Weak<T>

Source§

type Target = T

Source§

fn into_raw(self) -> *mut T

Source§

unsafe fn from_raw(ptr: *mut T) -> Self

Source§

impl<T: ViaRawPointer> ViaRawPointer for Option<T>
where T::Target: Sized,

Source§

type Target = <T as ViaRawPointer>::Target

Source§

fn into_raw(self) -> *mut Self::Target

Source§

unsafe fn from_raw(ptr: *mut Self::Target) -> Self

Source§

impl<T: ?Sized> ViaRawPointer for Box<T>

Source§

type Target = T

Source§

fn into_raw(self) -> *mut T

Source§

unsafe fn from_raw(ptr: *mut T) -> Self

Source§

impl<T: ?Sized> ViaRawPointer for Rc<T>

Source§

type Target = T

Source§

fn into_raw(self) -> *mut T

Source§

unsafe fn from_raw(ptr: *mut T) -> Self

Source§

impl<T: ?Sized> ViaRawPointer for Arc<T>

Source§

type Target = T

Source§

fn into_raw(self) -> *mut T

Source§

unsafe fn from_raw(ptr: *mut T) -> Self

Implementors§