NordSecurity / uniffi-bindgen-go

Uniffi bindings generator for Golang
Mozilla Public License 2.0
65 stars 18 forks source link

Use of callback interface results in compile errors #22

Closed nymoral closed 7 months ago

nymoral commented 8 months ago

Bindings from callback interface result in compile error: ./worker.go:717:70: could not determine kind of name for C.worker_78d8_cgo_UniFfiHttpClient

[Error]
enum ClientError {
    "InternalError",
};

callback interface UniFFIHttpClient {
    [Throws=ClientError]
    i32 post(string path, sequence<string> header, string body_b64);
};

namespace worker {
    u32 worker_start(
        boolean compression,
        UniFFIHttpClient ffi_client
    );
};
uniffi::include_scaffolding!("worker");

#[derive(Debug, thiserror::Error)]
pub enum ClientError {
    #[error("Internal error occurred")]
    InternalError,
}

impl From<uniffi::UnexpectedUniFFICallbackError> for ClientError {
    fn from(_: uniffi::UnexpectedUniFFICallbackError) -> Self {
        ClientError::InternalError
    }
}

pub trait UniFFIHttpClient: Send + Sync {
   fn post(&self, path: String, headers: Vec<String>, body_b64: String) -> Result<i32, ClientError>;
}

pub fn worker_start(
    compression: bool,
    ffi_client: Box<dyn UniFFIHttpClient>,
) -> u32 {
    return 0;
}