easydonate_api/result/
mod.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Deserialize, Serialize, Debug)]
14pub struct EasySuccessfullResponse<T: Serialize> {
15 success: bool,
16 response: T,
17}
18
19#[derive(Deserialize, Serialize, Debug)]
29pub struct EasyErrorResponse {
30 success: bool,
31 response: String,
32 error_code: i64
33}
34
35#[derive(Deserialize, Serialize, Debug)]
36#[serde(untagged)]
37pub enum EasyResponse<T: Serialize> {
38 Error(EasyErrorResponse),
39 Successfull(EasySuccessfullResponse<T>),
40}
41
42impl<T: Serialize> EasyResponse<T> {
43 pub fn result(self) -> anyhow::Result<T> {
44 match self {
45 EasyResponse::Successfull(success) => Ok(success.response),
46 EasyResponse::Error(err) => Err(anyhow::anyhow!("{} (error_code {})", err.response, err.error_code)),
47 }
48 }
49}
50
51pub type EasyResult<T> = Result<T, anyhow::Error>;