Skip to main content

ForeignTypeRef

Trait ForeignTypeRef 

Source
pub unsafe trait ForeignTypeRef: Sized {
    type CType;

    // Provided methods
    unsafe fn from_ptr<'a>(ptr: *mut Self::CType) -> &'a Self { ... }
    unsafe fn from_ptr_mut<'a>(ptr: *mut Self::CType) -> &'a mut Self { ... }
    fn as_ptr(&self) -> *mut Self::CType { ... }
}
Expand description

A trait implemented by types which reference borrowed foreign types.

§Safety

Implementations of ForeignTypeRef must guarantee the following:

  • Self::from_ptr(x).as_ptr() == x
  • Self::from_mut_ptr(x).as_ptr() == x

Required Associated Types§

Source

type CType

The raw C type.

Provided Methods§

Source

unsafe fn from_ptr<'a>(ptr: *mut Self::CType) -> &'a Self

Constructs a shared instance of this type from its raw type.

§Safety

ptr must be a valid, immutable, instance of the type for the 'a lifetime.

Source

unsafe fn from_ptr_mut<'a>(ptr: *mut Self::CType) -> &'a mut Self

Constructs a mutable reference of this type from its raw type.

§Safety

ptr must be a valid, unique, instance of the type for the 'a lifetime.

Source

fn as_ptr(&self) -> *mut Self::CType

Returns a raw pointer to the wrapped value.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§