Attribute Macro rusty_bind::binding_wrapper

source ·
#[binding_wrapper]
Expand description

Example Rust module that can be translated:

mod our_ffi_module {
    use rusty_bind::binding_wrapper;
    use std::sync::{Arc, Mutex};


    // Define Error type and `()` type.
    type ErrorType = String;
    type VoidType = ();

    pub trait SomeTrait: std::fmt::Debug {
        fn some_trait_method(&self);
    }

    #[derive(Clone, Debug)]
    pub struct Foo(u32);
    impl SomeTrait for Foo {
        fn some_trait_method(&self) {
        }
    }

    #[derive(Clone, Debug)]
    pub struct CustomType(u32);
    impl CustomType {
        pub fn return_another_custom_type(&self) -> AnotherCustomType {
            AnotherCustomType(20u64)
        }
    }

    #[derive(Clone, Debug)]
    pub struct AnotherCustomType(u64);
    impl AnotherCustomType {
        pub fn take_primitive_type_and_return_primitive_type(&self, a: u32) -> String {
            "Result".to_owned()
        }
    }

    #[binding_wrapper(source = "path/to/generated/rs/file")]
    mod ffi {
        extern "Rust" {
            type CustomType;
            fn return_another_custom_type(self: &CustomType) -> AnotherCustomType;

            type AnotherCustomType;

            #[cfg(target_os = "macos")]
            fn take_primitive_type_and_return_primitive_type(self: &AnotherCustomType, a: u32) -> String;

            fn some_trait_method(self: &Arc<Mutex<dyn SomeTrait>>);
            type ErrorType;
        }
    }
}