This repository has been archived on 2024-05-26. You can view files and clone it, but cannot push or open issues or pull requests.
trixy/tests/.template/expected.md

1.5 KiB

Host files

File path: out/dir/api.rs

// Host code
/* Rust API */
#[derive(Debug)]
pub enum Commands {
    #[allow(non_camel_case_types)]
    print { message: String },
    Trinitrix(trinitrix::Trinitrix),
}
pub mod trinitrix {
    #[derive(Debug)]
    pub enum Trinitrix {
        #[allow(non_camel_case_types)]
        hi { trixy_output: trixy::oneshot::Sender<trixy::types::String>, name: String },
    }
}
/* C API */
#[no_mangle]
pub extern "C" fn print(message: String) -> core::ffi::c_int {
    callback_function(print);
    return 1;
}
pub mod trinitrix_c {}
#[no_mangle]
pub extern "C" fn trinitrix_hi(
    output: *mut trixy::types::String,
    name: String,
) -> core::ffi::c_int {
    let output_val: trixy::types::String = {
        let (tx, rx) = trixy::oneshot::channel();
        callback_function(trinitrix_hi);
        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;
}
// vim: filetype=rust

Auxiliary files

File path: dist/interface.h

#if !defined TRIXY_MAIN_HEADER
#define TRIXY_MAIN_HEADER

#include "errno.h"
#include "string.h"
#include "vec.h"

extern int print (const char *message);

extern int trinitrix_hi (const char **trixy_output, const char *name);

struct trinitrix
{
  int (*hi) (const char **, const char *);
};

const struct trinitrix trinitrix = {
  .hi = trinitrix_hi,
};

#endif // if !defined TRIXY_MAIN_HEADER
// vim: filetype=c