pub trait IntoForeign: FreeForeign {
type Storage: 'static;
// Required method
fn into_foreign(
self,
) -> BorrowedPointer<'static, Self::Foreign, Self::Storage>;
}Expand description
A type for which a C representation can be created by consuming the Rust representation, hopefully without cloning much of the internal data.
Required Associated Types§
Sourcetype Storage: 'static
type Storage: 'static
The type of any extra data that are needed while the BorrowedPointer is alive.
Usually Self, though does not have to be. For example,
into_foreign() could discard the
unnecessary parts of self or perform other conversions. In
particular, a Cow<'_, str> will use a CString as the storage.
Required Methods§
Sourcefn into_foreign(self) -> BorrowedPointer<'static, Self::Foreign, Self::Storage>
fn into_foreign(self) -> BorrowedPointer<'static, Self::Foreign, Self::Storage>
Return a wrapper for a C representation of self. The wrapper
becomes the owner of self and allows access via a constant pointer.
let s = "Hello, world!".to_string();
let borrowed = s.into_foreign();
let len = unsafe { libc::strlen(borrowed.as_ptr()) };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.