Trait ffizz_passby::PassByValue
source · pub trait PassByValue: Sized {
type CType: Sized;
unsafe fn from_ctype(cval: Self::CType) -> Self;
fn into_ctype(self) -> Self::CType;
unsafe fn val_from_arg(arg: Self::CType) -> Self { ... }
unsafe fn return_val(self) -> Self::CType { ... }
unsafe fn val_to_arg_out(self, arg_out: *mut Self::CType) { ... }
}Expand description
This trait supports passing data to Rust by value.
Pass-by-values implies that values are copyable, via assignment in C, so this trait is typically used to represent Copy values, and in particular values that do not contain pointers.
The Rust and C types may differ, with PassByValue::from_ctype and PassByValue::into_ctype
converting between them. These typically provide some simple conversion between a C-style
data structure and a more ergonomic Rust type.
Required Associated Types§
Required Methods§
sourceunsafe fn from_ctype(cval: Self::CType) -> Self
unsafe fn from_ctype(cval: Self::CType) -> Self
Convert a C value to a Rust value.
Safety
The implementation of this method assumes that cval is a valid instance of Self::CType.
sourcefn into_ctype(self) -> Self::CType
fn into_ctype(self) -> Self::CType
Convert a Rust value to a C value.
Provided Methods§
sourceunsafe fn val_from_arg(arg: Self::CType) -> Self
unsafe fn val_from_arg(arg: Self::CType) -> Self
Copy a value from C as an argument.
Safety
selfmust be a valid instance of the C type. This is typically ensured either by requiring that C code not modify it, or by defining the valid values in C comments.
sourceunsafe fn return_val(self) -> Self::CType
unsafe fn return_val(self) -> Self::CType
Return a value to C
Safety
- if the value is allocated, the caller must ensure that the value is eventually freed
sourceunsafe fn val_to_arg_out(self, arg_out: *mut Self::CType)
unsafe fn val_to_arg_out(self, arg_out: *mut Self::CType)
Return a value to C, via an “output parameter”.
This is common in functions returning a new value along with some success indication.
Safety
arg_outmust not be NULL and must be properly aligned and pointing to valid memory of the size of CType.