#[repr(C)]pub struct CStringArray {
pub data: *const *const c_char,
pub size: usize,
}Expand description
A #[repr(C)] mirror of Vec<String> with impls of CReprOf, CDrop
and AsRust.
Layout is a (data, size) pair where data is a pointer to a
heap-allocated array of *const c_char, each pointing to its own
nul-terminated C string allocated by the Rust side. The whole structure
is freed via CDrop / Drop.
Strings containing interior NUL bytes cannot be represented and will
cause CReprOf::c_repr_of to fail
with CReprOfError::StringContainsNullBit.
§Example
use ffi_convert::{AsRust, CReprOf};
use ffi_convert_extra_ctypes::CStringArray;
let pizza_names = vec![
"Diavola".to_string(),
"Margarita".to_string(),
"Regina".to_string(),
];
let c_pizza_names = CStringArray::c_repr_of(pizza_names.clone()).unwrap();
assert_eq!(c_pizza_names.size, 3);
// Deep-copy back into owned Rust strings.
let round_tripped: Vec<String> = c_pizza_names.as_rust().unwrap();
assert_eq!(round_tripped, pizza_names);Fields§
§data: *const *const c_charPointer to the first *const c_char element of the array.
size: usizeNumber of elements in the array.
Trait Implementations§
Source§impl CDrop for CStringArray
impl CDrop for CStringArray
Source§impl Debug for CStringArray
impl Debug for CStringArray
Source§impl Drop for CStringArray
impl Drop for CStringArray
Source§impl RawPointerConverter<CStringArray> for CStringArray
impl RawPointerConverter<CStringArray> for CStringArray
Source§fn into_raw_pointer(self) -> *const CStringArray
fn into_raw_pointer(self) -> *const CStringArray
Leak the value behind a raw pointer. Pair with
Self::from_raw_pointer
or Self::drop_raw_pointer to release the allocation.Source§fn into_raw_pointer_mut(self) -> *mut CStringArray
fn into_raw_pointer_mut(self) -> *mut CStringArray
Leak the value behind a mutable raw pointer. Pair with
Self::from_raw_pointer_mut or Self::drop_raw_pointer_mut to
release the allocation.Source§unsafe fn from_raw_pointer_mut(
input: *mut CStringArray,
) -> Result<CStringArray, UnexpectedNullPointerError>
unsafe fn from_raw_pointer_mut( input: *mut CStringArray, ) -> Result<CStringArray, UnexpectedNullPointerError>
Take back ownership of a raw pointer previously produced by
Self::into_raw_pointer_mut. Returns UnexpectedNullPointerError
if input is null. Read moreSource§unsafe fn from_raw_pointer(
input: *const CStringArray,
) -> Result<CStringArray, UnexpectedNullPointerError>
unsafe fn from_raw_pointer( input: *const CStringArray, ) -> Result<CStringArray, UnexpectedNullPointerError>
Take back ownership of a raw pointer previously produced by
Self::into_raw_pointer. Returns UnexpectedNullPointerError if
input is null. Read moreSource§unsafe fn drop_raw_pointer(
input: *const T,
) -> Result<(), UnexpectedNullPointerError>
unsafe fn drop_raw_pointer( input: *const T, ) -> Result<(), UnexpectedNullPointerError>
Take back ownership of a pointer produced by
Self::into_raw_pointer
and drop the value. Read moreSource§unsafe fn drop_raw_pointer_mut(
input: *mut T,
) -> Result<(), UnexpectedNullPointerError>
unsafe fn drop_raw_pointer_mut( input: *mut T, ) -> Result<(), UnexpectedNullPointerError>
Take back ownership of a pointer produced by
Self::into_raw_pointer_mut
and drop the value. Read moreimpl Sync for CStringArray
Auto Trait Implementations§
impl !Send for CStringArray
impl Freeze for CStringArray
impl RefUnwindSafe for CStringArray
impl Unpin for CStringArray
impl UnsafeUnpin for CStringArray
impl UnwindSafe for CStringArray
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> RawBorrow<T> for T
impl<T> RawBorrow<T> for T
Source§unsafe fn raw_borrow<'a>(
input: *const T,
) -> Result<&'a T, UnexpectedNullPointerError>
unsafe fn raw_borrow<'a>( input: *const T, ) -> Result<&'a T, UnexpectedNullPointerError>
Source§impl<T> RawBorrowMut<T> for T
impl<T> RawBorrowMut<T> for T
Source§unsafe fn raw_borrow_mut<'a>(
input: *mut T,
) -> Result<&'a mut T, UnexpectedNullPointerError>
unsafe fn raw_borrow_mut<'a>( input: *mut T, ) -> Result<&'a mut T, UnexpectedNullPointerError>
Borrow the value behind
input mutably, or return
UnexpectedNullPointerError if it is null. Read more