pub struct ApiResult<T> {
pub success: bool,
pub data: Option<ResponseData<T>>,
pub message: Option<String>,
pub code: Option<i32>,
pub pagination: Option<ResultPagination>,
pub errors: Option<Vec<FieldError>>,
pub trace_id: Option<String>,
pub extra: Option<Value>,
}Expand description
API response wrapper with unified structure
Fields§
§success: bool§data: Option<ResponseData<T>>§message: Option<String>§code: Option<i32>§pagination: Option<ResultPagination>§errors: Option<Vec<FieldError>>§trace_id: Option<String>§extra: Option<Value>Implementations§
Source§impl<T> ApiResult<T>
impl<T> ApiResult<T>
Sourcepub fn success() -> Self
pub fn success() -> Self
Create a successful response without data
Alias for ok() - use ok() for clarity
Sourcepub fn validation_errors(errors: Vec<FieldError>) -> Self
pub fn validation_errors(errors: Vec<FieldError>) -> Self
Create a validation error response with field-level details
Sourcepub fn from_result<E: Display>(result: Result<T, E>) -> Self
pub fn from_result<E: Display>(result: Result<T, E>) -> Self
Convert a Result<T, E> into ApiResult<T>, mapping all errors to InternalError
Sourcepub fn with_extra(self, key: &str, value: Value) -> Self
pub fn with_extra(self, key: &str, value: Value) -> Self
Add extra metadata to the response
Sourcepub fn with_pagination(self, pagination: ResultPagination) -> Self
pub fn with_pagination(self, pagination: ResultPagination) -> Self
Set pagination metadata for list responses
Sourcepub fn with_message(self, message: &str) -> Self
pub fn with_message(self, message: &str) -> Self
Set message for the response
Sourcepub fn with_errors(self, errors: Vec<FieldError>) -> Self
pub fn with_errors(self, errors: Vec<FieldError>) -> Self
Set field-level validation errors
Sourcepub fn with_error(
self,
field: impl Into<String>,
message: impl Into<String>,
) -> Self
pub fn with_error( self, field: impl Into<String>, message: impl Into<String>, ) -> Self
Add a single field-level validation error
Sourcepub fn with_trace_id(self, id: impl Into<String>) -> Self
pub fn with_trace_id(self, id: impl Into<String>) -> Self
Set request trace ID
Trait Implementations§
Source§impl<'de, T> Deserialize<'de> for ApiResult<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for ApiResult<T>where
T: Deserialize<'de>,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<T, E: Display + Debug> From<Result<T, E>> for ApiResult<T>
Convert any Result<T, E> where E implements Display to ApiResult<T>
impl<T, E: Display + Debug> From<Result<T, E>> for ApiResult<T>
Convert any Result<T, E> where E implements Display to ApiResult<T>
Source§impl<T: Serialize> Responder for ApiResult<T>
Available on crate feature actix only.Actix-web framework integration for ApiResult
impl<T: Serialize> Responder for ApiResult<T>
Available on crate feature
actix only.Actix-web framework integration for ApiResult
type Body = BoxBody
Source§fn respond_to(self, _req: &HttpRequest) -> HttpResponse<Self::Body>
fn respond_to(self, _req: &HttpRequest) -> HttpResponse<Self::Body>
Convert self to
HttpResponse.Auto Trait Implementations§
impl<T> Freeze for ApiResult<T>where
T: Freeze,
impl<T> RefUnwindSafe for ApiResult<T>where
T: RefUnwindSafe,
impl<T> Send for ApiResult<T>where
T: Send,
impl<T> Sync for ApiResult<T>where
T: Sync,
impl<T> Unpin for ApiResult<T>where
T: Unpin,
impl<T> UnsafeUnpin for ApiResult<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for ApiResult<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more