Trait interoptopus::patterns::result::FFIError [−][src]
Expand description
A trait you should implement for enums that signal errors in FFI calls.
Once implemented, the enum can be used in services to automatically
convert Result<(), E>
types to FFI enums.
Example
use interoptopus::patterns::result::FFIError;
use interoptopus::ffi_type;
// Some Error used in your application.
pub enum Error {
Bad,
}
// The error FFI users should see
#[ffi_type(patterns(ffi_error))]
#[repr(C)]
enum MyFFIError {
Ok = 0,
NullPassed = 1,
Panic = 2,
OtherError = 3,
}
// Gives special meaning to some of your error variants.
impl FFIError for MyFFIError {
const SUCCESS: Self = Self::Ok;
const NULL: Self = Self::NullPassed;
const PANIC: Self = Self::Panic;
}
// How to map an `Error` to an `MyFFIError`.
impl From<Error> for MyFFIError {
fn from(x: Error) -> Self {
match x {
Error::Bad => Self::OtherError,
}
}
}
Associated Constants
The variant to return when everything went OK, usually the variant with value 0
.