value_box_ffi/
lib.rs

1#![allow(non_snake_case)]
2
3#[cfg(feature = "array-box")]
4extern crate array_box;
5#[cfg(feature = "geometry-box")]
6extern crate geometry_box;
7#[cfg(feature = "phlow")]
8#[macro_use]
9extern crate phlow;
10#[cfg(feature = "string-box")]
11extern crate string_box;
12
13#[cfg(feature = "phlow")]
14use phlow_extensions::CoreExtensions;
15
16#[cfg(feature = "value-box")]
17pub use crate::value_box_ffi::*;
18#[cfg(feature = "array-box")]
19pub use array_box_ffi::*;
20#[cfg(feature = "geometry-box")]
21pub use geometry_box_ffi::*;
22#[cfg(feature = "string-box")]
23pub use string_box_ffi::*;
24
25#[cfg(feature = "array-box")]
26mod array_box_ffi;
27#[cfg(feature = "geometry-box")]
28mod geometry_box_ffi;
29#[cfg(feature = "string-box")]
30mod string_box_ffi;
31#[cfg(feature = "value-box")]
32mod value_box_ffi;
33
34#[no_mangle]
35pub extern "C" fn boxer_test() -> bool {
36    return true;
37}
38
39#[cfg(feature = "phlow")]
40import_extensions!(CoreExtensions);
41
42#[no_mangle]
43#[cfg(feature = "phlow")]
44pub fn boxer_value_box_to_phlow_object(
45    value_box: *mut value_box::ValueBox<&'static (dyn std::any::Any + 'static)>,
46) -> *mut std::ffi::c_void {
47    if value_box.is_null() {
48        return std::ptr::null_mut()
49    }
50
51    let mut value_box = std::mem::ManuallyDrop::new(unsafe { Box::from_raw(value_box) });
52    value_box
53        .phlow_object()
54        .map(|phlow_object| {
55            value_box::ValueBox::new(phlow_object).into_raw() as *mut std::ffi::c_void
56        })
57        .unwrap_or(std::ptr::null_mut())
58}
59
60#[no_mangle]
61#[cfg(not(feature = "phlow"))]
62pub fn boxer_value_box_to_phlow_object(
63    _value_box: *mut value_box::ValueBox<std::ffi::c_void>,
64) -> *mut std::ffi::c_void {
65    std::ptr::null_mut()
66}