#[derive(trixy::__private::thiserror::Error)]
#[allow(non_camel_case_types)]
#[derive(Debug)]
pub enum Err {
#[error("This should be unreachable.")]
__never,
}
impl From<crate::Err_c> for Err {
fn from(value: crate::Err_c) -> Self {
match value {
crate::Err_c::__never => Self::__never,
}
}
}
#[derive(Debug)]
pub enum Commands {
#[allow(non_camel_case_types)]
void_input {
trixy_output: trixy::oneshot::Sender<crate::Result_void_Err>,
},
}
#[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 }
}
}
#[allow(non_camel_case_types)]
#[repr(C)]
pub union Result_void_Err_value {
ok: std::mem::ManuallyDrop<()>,
err: std::mem::ManuallyDrop<crate::Err_c>,
}
#[allow(non_camel_case_types)]
#[repr(C)]
pub struct Result_void_Err {
tag: trixy::types::ResultTag,
value: Result_void_Err_value,
}
impl std::fmt::Debug for Result_void_Err {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self.tag {
trixy::types::ResultTag::Ok => write!(f, "{:?}", unsafe { &self.value.ok }),
trixy::types::ResultTag::Err => {
write!(f, "{:?}", unsafe { &self.value.err })
}
}
}
}
impl trixy::types::traits::convert_trait::Convertible for crate::OurResult<(), crate::Err_c> {
type Ptr = Result_void_Err;
fn into_ptr(self) -> Self::Ptr {
if self.value.is_ok() {
Self::Ptr {
tag: trixy::types::ResultTag::Ok,
value: Result_void_Err_value {
ok: std::mem::ManuallyDrop::new(self.value.expect("Is ok")),
},
}
} else {
Self::Ptr {
tag: trixy::types::ResultTag::Err,
value: Result_void_Err_value {
err: std::mem::ManuallyDrop::new(self.value.expect_err("Is err")),
},
}
}
}
fn from_ptr(_ptr: Self::Ptr) -> Result<Self, trixy::types::error::TypeConversionError> {
unreachable!("This should probably not be called?");
}
}
#[derive(trixy::__private::thiserror::Error)]
#[allow(non_camel_case_types)]
#[repr(C)]
#[derive(Debug)]
pub enum Err_c {
#[error("This should be unreachable.")]
__never,
}
impl From<crate::Err> for Err_c {
fn from(value: crate::Err) -> Self {
match value {
crate::Err::__never => Self::__never,
}
}
}
#[no_mangle]
pub extern "C" fn void_input(output: *mut crate::Result_void_Err) -> core::ffi::c_int {
let output_val: crate::Result_void_Err = {
let (tx, rx) = trixy::oneshot::channel();
let error = std::panic::catch_unwind(|| {
crate::callback_function(crate::Commands::void_input { trixy_output: tx });
0
});
if let Err(_) = error {
eprintln!("Catched a panic just before the c ffi.");
std::process::exit(1);
}
let recv = rx
.recv()
.expect("The channel should not be closed until this value is received");
recv.into()
};
unsafe {
std::ptr::write(output, output_val);
}
return 1;
}