mirror of
https://github.com/logos-messaging/logos-messaging-rust-bindings.git
synced 2026-01-02 14:03:12 +00:00
Added JsonResponse type
This commit is contained in:
parent
5c35417f49
commit
a89d62683c
26
waku/src/general/mod.rs
Normal file
26
waku/src/general/mod.rs
Normal 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),
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user