pub struct ApiResponse<T> {
pub success: bool,
pub data: Option<T>,
pub error: Option<ApiError>,
pub message: Option<String>,
}
Expand description
Standard API response wrapper
Fields§
§success: bool
§data: Option<T>
§error: Option<ApiError>
§message: Option<String>
Implementations§
Source§impl<T> ApiResponse<T>
impl<T> ApiResponse<T>
Sourcepub fn cast<U>(self) -> ApiResponse<U>
pub fn cast<U>(self) -> ApiResponse<U>
Convert this ApiResponse to another type (for error responses)
Sourcepub fn forbidden_typed() -> ApiResponse<T>
pub fn forbidden_typed() -> ApiResponse<T>
Create a forbidden response for any type
Create an unauthorized response for any type
Sourcepub fn error_typed(code: &str, message: impl Into<String>) -> ApiResponse<T>
pub fn error_typed(code: &str, message: impl Into<String>) -> ApiResponse<T>
Create an error response for any type
Sourcepub fn validation_error_typed(message: impl Into<String>) -> ApiResponse<T>
pub fn validation_error_typed(message: impl Into<String>) -> ApiResponse<T>
Create a validation error response for any type
Sourcepub fn not_found_typed(message: impl Into<String>) -> ApiResponse<T>
pub fn not_found_typed(message: impl Into<String>) -> ApiResponse<T>
Create a not found response for any type
Sourcepub fn forbidden_with_message_typed(
message: impl Into<String>,
) -> ApiResponse<T>
pub fn forbidden_with_message_typed( message: impl Into<String>, ) -> ApiResponse<T>
Create a forbidden response with message for any type
Sourcepub fn error_with_message_typed(
code: &str,
message: impl Into<String>,
) -> ApiResponse<T>
pub fn error_with_message_typed( code: &str, message: impl Into<String>, ) -> ApiResponse<T>
Create an error response with message for any type
Sourcepub fn not_found_with_message_typed(
message: impl Into<String>,
) -> ApiResponse<T>
pub fn not_found_with_message_typed( message: impl Into<String>, ) -> ApiResponse<T>
Create a not found response with message for any type
Sourcepub fn internal_error_typed() -> ApiResponse<T>
pub fn internal_error_typed() -> ApiResponse<T>
Create an internal error response for any type
Sourcepub fn success_with_message(data: T, message: impl Into<String>) -> Self
pub fn success_with_message(data: T, message: impl Into<String>) -> Self
Create successful response with message
Sourcepub fn ok() -> ApiResponse<()>
pub fn ok() -> ApiResponse<()>
Create simple success response
Sourcepub fn ok_with_message(message: impl Into<String>) -> ApiResponse<()>
pub fn ok_with_message(message: impl Into<String>) -> ApiResponse<()>
Create success response with message only
Source§impl ApiResponse<()>
impl ApiResponse<()>
Sourcepub fn error(code: impl Into<String>, message: impl Into<String>) -> Self
pub fn error(code: impl Into<String>, message: impl Into<String>) -> Self
Create error response
Sourcepub fn error_with_details(
code: impl Into<String>,
message: impl Into<String>,
details: Value,
) -> Self
pub fn error_with_details( code: impl Into<String>, message: impl Into<String>, details: Value, ) -> Self
Create error response with details
Sourcepub fn validation_error(message: impl Into<String>) -> Self
pub fn validation_error(message: impl Into<String>) -> Self
Create validation error
Create unauthorized error
Sourcepub fn forbidden_with_message(message: impl Into<String>) -> Self
pub fn forbidden_with_message(message: impl Into<String>) -> Self
Create forbidden error with custom message
Sourcepub fn not_found_with_message(message: impl Into<String>) -> Self
pub fn not_found_with_message(message: impl Into<String>) -> Self
Create not found error with custom message
Sourcepub fn error_with_message(
code: impl Into<String>,
message: impl Into<String>,
) -> Self
pub fn error_with_message( code: impl Into<String>, message: impl Into<String>, ) -> Self
Create error response with custom message
Sourcepub fn internal_error() -> Self
pub fn internal_error() -> Self
Create internal server error
Trait Implementations§
Source§impl<T: Debug> Debug for ApiResponse<T>
impl<T: Debug> Debug for ApiResponse<T>
Source§impl<T> IntoResponse for ApiResponse<T>where
T: Serialize,
impl<T> IntoResponse for ApiResponse<T>where
T: Serialize,
Source§fn into_response(self) -> Response
fn into_response(self) -> Response
Auto Trait Implementations§
impl<T> Freeze for ApiResponse<T>where
T: Freeze,
impl<T> RefUnwindSafe for ApiResponse<T>where
T: RefUnwindSafe,
impl<T> Send for ApiResponse<T>where
T: Send,
impl<T> Sync for ApiResponse<T>where
T: Sync,
impl<T> Unpin for ApiResponse<T>where
T: Unpin,
impl<T> UnwindSafe for ApiResponse<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more