#[derive(Debug)]
pub enum Commands {
#[allow(non_camel_case_types)]
call_me_back_outstanding {
callback: extern "C" fn(trixy::types::String) -> trixy::types::String,
},
One(one::One),
}
pub mod one {
#[derive(Debug)]
pub enum One {
#[allow(non_camel_case_types)]
call_me_back {
callback: extern "C" fn(trixy::types::u32),
},
}
}
#[derive(Debug)]
pub struct OurResult<T, E> {
value: Result<T, E>,
}
impl<T, E> std::ops::Deref for OurResult<T, E> {
type Target = Result<T, E>;
fn deref(&self) -> &Self::Target {
&self.value
}
}
impl<T, E> From<Result<T, E>> for OurResult<T, E> {
fn from(value: Result<T, E>) -> Self {
Self { value }
}
}
#[derive(Debug)]
pub struct OurOption<T> {
value: Option<T>,
}
impl<T> std::ops::Deref for OurOption<T> {
type Target = Option<T>;
fn deref(&self) -> &Self::Target {
&self.value
}
}
impl<T> From<Option<T>> for OurOption<T> {
fn from(value: Option<T>) -> Self {
Self { value }
}
}
#[derive(Debug)]
pub struct OurVec<T> {
value: Vec<T>,
}
impl<T> std::ops::Deref for OurVec<T> {
type Target = Vec<T>;
fn deref(&self) -> &Self::Target {
&self.value
}
}
impl<T> From<Vec<T>> for OurVec<T> {
fn from(value: Vec<T>) -> Self {
Self { value }
}
}
pub mod one_c {}
#[no_mangle]
pub extern "C" fn one_call_me_back(callback: extern "C" fn(trixy::types::u32)) -> core::ffi::c_int {
let error = std::panic::catch_unwind(|| {
crate::callback_function(crate::Commands::One(crate::one::One::call_me_back {
callback: match callback.try_into() {
Ok(ok) => ok,
Err(err) => {
trixy::types::traits::errno::set(err.into());
return 0;
}
},
}));
0
});
if let Err(_) = error {
eprintln!("Catched a panic just before the c ffi.");
std::process::exit(1);
}
return 1;
}
#[no_mangle]
pub extern "C" fn call_me_back_outstanding(
callback: extern "C" fn(trixy::types::String) -> trixy::types::String,
) -> core::ffi::c_int {
let error = std::panic::catch_unwind(|| {
crate::callback_function(crate::Commands::call_me_back_outstanding {
callback: match callback.try_into() {
Ok(ok) => ok,
Err(err) => {
trixy::types::traits::errno::set(err.into());
return 0;
}
},
});
0
});
if let Err(_) = error {
eprintln!("Catched a panic just before the c ffi.");
std::process::exit(1);
}
return 1;
}