Trait capi::ToCOwned [] [src]

pub trait ToCOwned<T: Send> {
    unsafe fn to_c_owned(self) -> *const T;
    unsafe fn to_c_owned_mut(self) -> *mut T;
}

Takes a Box and returns a C pointer that can be given to a C program to use for as long as it wants.

use capi::ToCOwned;
struct Foo;

#[no_mangle]
unsafe extern "C" fn create_foo() -> *const Foo {
    Box::new(Foo).to_c_owned()
}

Required Methods

unsafe fn to_c_owned(self) -> *const T

Takes a box and returns a const C pointer to box's content without freeing the box.

To take ownership of the box back (and to let Rust free its content) use ptr.to_owned_from_c().

unsafe fn to_c_owned_mut(self) -> *mut T

Takes a mutable box and returns a C pointer to box's content without freeing the box.

To take ownership of the box back (and to let Rust free its content) use ptr.to_owned_from_c_mut().

Implementors