pub unsafe trait FixedAlloc:
CloneToForeign
+ FromForeign
+ FreeForeign
+ Sized {
// Required method
unsafe fn clone_into_foreign(dest: *mut Self::Foreign, src: &Self);
// Provided methods
unsafe fn clone_array_from_foreign<const N: usize>(
src: *const Self::Foreign,
) -> [Self; N] { ... }
unsafe fn clone_from_native_slice(dest: *mut Self::Foreign, src: &[Self]) { ... }
}Expand description
A type which is stored in a fixed amount of memory given by
mem::size_of::<Self::Foreign>().
§Safety
Define this trait only if CloneToForeign allocates a single memory block,
of constant size mem::size_of::<Self::Foreign>().
Required Methods§
Sourceunsafe fn clone_into_foreign(dest: *mut Self::Foreign, src: &Self)
unsafe fn clone_into_foreign(dest: *mut Self::Foreign, src: &Self)
Convert a native Rust object to a foreign C struct, copying
everything pointed to by self (same as to_glib_full in glib-rs)
let mut dest = MaybeUninit::uninit();
unsafe {
u8::clone_into_foreign(dest.as_mut_ptr(), &42);
assert_eq!(dest.assume_init(), 42);
}§Safety
dest must be allocated and writable.
Provided Methods§
Sourceunsafe fn clone_array_from_foreign<const N: usize>(
src: *const Self::Foreign,
) -> [Self; N]
unsafe fn clone_array_from_foreign<const N: usize>( src: *const Self::Foreign, ) -> [Self; N]
Copy src.len() elements into memory at address dest.
let src: [u8; 3] = [1, 2, 3];
let dest: [u8; 3] = unsafe {
u8::clone_array_from_foreign(src.as_ptr())
};
assert_eq!(dest, src);§Safety
src must be allocated, large enough to host N values of type
Self::Foreign, and readable.
Sourceunsafe fn clone_from_native_slice(dest: *mut Self::Foreign, src: &[Self])
unsafe fn clone_from_native_slice(dest: *mut Self::Foreign, src: &[Self])
Copy src.len() elements into memory at address dest.
let mut dest: MaybeUninit::<[u8; 3]> = MaybeUninit::uninit();
unsafe {
u8::clone_from_native_slice(dest.as_mut_ptr().cast(), &[1, 2, 3]);
assert_eq!(dest.assume_init(), [1, 2, 3]);
};§Safety
dest must be allocated, large enough to host N values of type
Self::Foreign, and writable.
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.