1use serde::{Deserialize, Serialize, de::DeserializeOwned};
2
3use crate::{
4 error::{ApiError, ErrorValue},
5 traits::FromBytes,
6};
7
8#[derive(Serialize, Deserialize, Debug)]
9#[cfg_attr(feature = "specta", derive(specta::Type))]
10pub struct ApiResponse<T> {
11 pub success: bool,
12 pub error: Option<ErrorValue>,
13 pub detail: Option<String>,
14 pub data: Option<T>,
15}
16
17impl<T> FromBytes for ApiResponse<T>
18where
19 T: DeserializeOwned,
20{
21 fn from_bytes(bytes: Vec<u8>) -> Result<Self, ApiError> {
22 serde_json::from_slice(&bytes).map_err(ApiError::from)
23 }
24}