Skip to main content

GCAbiConversion

Trait GCAbiConversion 

pub unsafe trait GCAbiConversion: Sized {
    type CType: Sized;

    // Required methods
    fn from_c(c_type: Self::CType) -> Self;
    fn into_c(self) -> Self::CType;

    // Provided methods
    fn ref_c(&self) -> &Self::CType { ... }
    fn from_c_ref(c_type: &Self::CType) -> &Self { ... }
    unsafe fn from_c_ptr(ptr: *const Self::CType) -> &'static Self { ... }
    unsafe fn as_ptr(&self) -> *const Self::CType { ... }
    unsafe fn as_mut_ptr(&mut self) -> *mut Self::CType { ... }
}
Expand description

Trait for converting between Rust and C types Provides methods for converting between raw and abstraction types.

§Safety

Implementors must ensure that GCAbiConversion::CType has the same memory layout as whatever implements GCAbiConversion

Required Associated Types§

type CType: Sized

Required Methods§

fn from_c(c_type: Self::CType) -> Self

Convert from the C type to the Rust type

fn into_c(self) -> Self::CType

Convert from the Rust type to the C type

Provided Methods§

fn ref_c(&self) -> &Self::CType

Get a reference to the C type

fn from_c_ref(c_type: &Self::CType) -> &Self

Get a reference to the converted type

unsafe fn from_c_ptr(ptr: *const Self::CType) -> &'static Self

Get a mutable reference to the C type

§Safety

Assumes the pointer is valid and not null The caller is responsible for dealing with the lifetime of the pointer

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

Get a immutable reference to the C type

§Safety

The caller is responsible for manually handle the lifetime of the pointer

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

Get a mutable reference to the C type

§Safety

The caller is responsible for dealing with the lifetime of the pointer Also, the caller must not mutate both the reference at pointer at the same time as this goes against the borrowing rules

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§