Trait ForeignType

Source
pub unsafe trait ForeignType: Sized {
    type CType;
    type Ref: ForeignTypeRef<CType = Self::CType>;

    // Required methods
    unsafe fn from_ptr(ptr: *mut Self::CType) -> Self;
    fn as_ptr(&self) -> *mut Self::CType;

    // Provided method
    fn into_ptr(self) -> *mut Self::CType { ... }
}
Expand description

A type implemented by wrappers over foreign types.

§Safety

Implementations of ForeignType must guarantee the following:

  • Self::from_ptr(x).as_ptr() == x
  • Self::from_ptr(x).into_ptr(x) == x
  • Self::from_ptr(x).deref().as_ptr(x) == x
  • Self::from_ptr(x).deref_mut().as_ptr(x) == x
  • Self::from_ptr(x).as_ref().as_ptr(x) == x
  • Self::from_ptr(x).as_mut().as_ptr(x) == x

Required Associated Types§

Source

type CType

The raw C type.

Source

type Ref: ForeignTypeRef<CType = Self::CType>

The type representing a reference to this type.

Required Methods§

Source

unsafe fn from_ptr(ptr: *mut Self::CType) -> Self

Constructs an instance of this type from its raw type.

§Safety

ptr must be a valid, owned instance of the native type.

Source

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

Returns a raw pointer to the wrapped value.

Provided Methods§

Source

fn into_ptr(self) -> *mut Self::CType

Consumes the wrapper and returns the raw pointer.

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.

Implementors§