Added JsonResponse type

This commit is contained in:
danielsanchezq 2022-09-23 09:19:08 +02:00
parent 5c35417f49
commit a89d62683c

26
waku/src/general/mod.rs Normal file
View File

@ -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<T> {
Result(T),
Error(String),
}
type Response<T> = Result<T, String>;
impl<T> From<JsonResponse<T>> for Response<T> {
fn from(response: JsonResponse<T>) -> Self {
match response {
JsonResponse::Result(t) => Ok(t),
JsonResponse::Error(e) => Err(e),
}
}
}