From a89d62683c08e5a977bb80c2bb56053a156d85f1 Mon Sep 17 00:00:00 2001 From: danielsanchezq Date: Fri, 23 Sep 2022 09:19:08 +0200 Subject: [PATCH] Added JsonResponse type --- waku/src/general/mod.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 waku/src/general/mod.rs diff --git a/waku/src/general/mod.rs b/waku/src/general/mod.rs new file mode 100644 index 0000000..f46e212 --- /dev/null +++ b/waku/src/general/mod.rs @@ -0,0 +1,26 @@ +// std + +// crates +use serde::Deserialize; +// internal + +/// JsonResponse wrapper. +/// `go-waku` ffi returns this type as a `char *` as per the [specification](https://rfc.vac.dev/spec/36/#jsonresponse-type) +/// +#[derive(Deserialize)] +#[serde(rename_all = "snake_case")] +pub(crate) enum JsonResponse { + Result(T), + Error(String), +} + +type Response = Result; + +impl From> for Response { + fn from(response: JsonResponse) -> Self { + match response { + JsonResponse::Result(t) => Ok(t), + JsonResponse::Error(e) => Err(e), + } + } +}