diff --git a/native/native_rust_library/Cargo.lock b/native/native_rust_library/Cargo.lock --- a/native/native_rust_library/Cargo.lock +++ b/native/native_rust_library/Cargo.lock @@ -217,6 +217,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" +[[package]] +name = "convert_case" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" + [[package]] name = "cpufeatures" version = "0.2.5" @@ -348,6 +354,19 @@ "syn", ] +[[package]] +name = "derive_more" +version = "0.99.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" +dependencies = [ + "convert_case", + "proc-macro2", + "quote", + "rustc_version", + "syn", +] + [[package]] name = "digest" version = "0.9.0" @@ -768,6 +787,7 @@ "comm-opaque2", "cxx", "cxx-build", + "derive_more", "lazy_static", "opaque-ke 1.2.0", "prost", @@ -1053,6 +1073,15 @@ "winapi", ] +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver", +] + [[package]] name = "scratch" version = "1.0.2" @@ -1072,6 +1101,12 @@ "zeroize", ] +[[package]] +name = "semver" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed" + [[package]] name = "serde" version = "1.0.144" diff --git a/native/native_rust_library/Cargo.toml b/native/native_rust_library/Cargo.toml --- a/native/native_rust_library/Cargo.toml +++ b/native/native_rust_library/Cargo.toml @@ -18,6 +18,7 @@ tracing = "0.1" regex = "1.6" comm-opaque2 = {path = "../../shared/comm-opaque2"} +derive_more = "0.99" [build-dependencies] cxx-build = "1.0" diff --git a/native/native_rust_library/src/lib.rs b/native/native_rust_library/src/lib.rs --- a/native/native_rust_library/src/lib.rs +++ b/native/native_rust_library/src/lib.rs @@ -105,7 +105,19 @@ include!("RustCallback.h"); #[namespace = "comm"] #[cxx_name = "stringCallback"] - fn string_callback(error: String, counter: u32, ret: String); + fn string_callback(error: String, promise_id: u32, ret: String); + } +} + +fn handle_string_result_as_callback( + result: Result, + promise_id: u32, +) where + E: std::fmt::Display, +{ + match result { + Err(e) => string_callback(e.to_string(), promise_id, "".to_string()), + Ok(r) => string_callback("".to_string(), promise_id, r), } } @@ -221,3 +233,13 @@ .expect("Failed to create Tokio runtime for the Tunnelbroker client"), }) } + +#[derive( + Debug, derive_more::Display, derive_more::From, derive_more::Error, +)] +pub enum Error { + #[display(...)] + TonicGRPC(Status), + #[display(...)] + TonicTransport(tonic::transport::Error), +}