pub struct ApiResponse<T> {
pub success: bool,
pub data: Option<T>,
pub error: Option<String>,
pub code: Option<&'static str>,
}Expand description
API response wrapper.
Fields§
§success: boolWhether the request did what was asked. Read this, not the presence of
data.
data: Option<T>The payload, on success.
error: Option<String>What went wrong, on failure.
code: Option<&'static str>A stable, machine-readable name for what went wrong, on failure.
error is prose and may be reworded; this is what a client should
match on. Absent on success, and on the few failures that predate it.
Implementations§
Source§impl<T: Serialize> ApiResponse<T>
impl<T: Serialize> ApiResponse<T>
Sourcepub fn error(message: impl Into<String>) -> ApiResponse<()>
pub fn error(message: impl Into<String>) -> ApiResponse<()>
A failure response carrying message and no data.
Returns ApiResponse<()> regardless of T: there is no payload to
type, and requiring the caller to name one at every error site would be
noise.
Sourcepub fn error_with_code(
code: &'static str,
message: impl Into<String>,
) -> ApiResponse<()>
pub fn error_with_code( code: &'static str, message: impl Into<String>, ) -> ApiResponse<()>
A failure response carrying a stable code as well as message.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for ApiResponse<T>
impl<T> RefUnwindSafe for ApiResponse<T>where
Option<T>: RefUnwindSafe,
impl<T> Send for ApiResponse<T>
impl<T> Sync for ApiResponse<T>
impl<T> Unpin for ApiResponse<T>
impl<T> UnsafeUnpin for ApiResponse<T>where
Option<T>: UnsafeUnpin,
impl<T> UnwindSafe for ApiResponse<T>where
Option<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
Mutably borrows from an owned value. Read more
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> ⓘ
Converts
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> ⓘ
Converts
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