Enum ApiResponse

Source
pub enum ApiResponse<Data, Meta> {
    Success(SuccessResponse<Data, Meta>),
    Error(ErrorResponse<Meta>),
}
Expand description

Enum to represent the overall API response

Variants§

§

Success(SuccessResponse<Data, Meta>)

§

Error(ErrorResponse<Meta>)

Implementations§

Source§

impl<Data, Meta> ApiResponse<Data, Meta>

Source

pub const fn new_success(data: Data, meta: Meta) -> Self

Source

pub const fn from_success(data: Data) -> Self

Source

pub const fn from_success_data(data: Data) -> Self

Source

pub const fn new_error(error: ApiError, meta: Meta) -> Self

Source

pub const fn from_error(error: ApiError) -> Self

Source

pub fn from_error_msg(code: impl Into<u32>, message: impl Into<String>) -> Self

Source

pub fn from_error_source( code: impl Into<u32>, source: impl Error + Send + Sync + 'static, set_source_detail: bool, message: Option<String>, ) -> Self

Source

pub fn with_meta(self, meta: Meta) -> Self

Source

pub fn set_meta(&mut self, meta: Meta) -> &mut Self

Source

pub const fn is_success(&self) -> bool

Source

pub const fn is_error(&self) -> bool

Source

pub const fn get_meta(&self) -> Option<&Meta>

Source

pub fn expect(self, expect_msg: &str) -> SuccessResponse<Data, Meta>

§Panics

If it is ApiResponse::Error, trigger a panic using the expect_msg parameter.

Source

pub fn unwrap(self) -> SuccessResponse<Data, Meta>

§Panics

If it is ApiResponse::Error, trigger a panic.

Source

pub fn unwrap_err(self) -> ErrorResponse<Meta>

§Panics

If it is ApiResponse::Success, trigger a panic.

Source

pub fn into_result(self) -> ApiResult<Data, Meta>

Source

pub fn into_result_data(self) -> Result<Data, ErrorResponse<Meta>>

Source

pub fn into_result_without_meta(self) -> Result<Data, ApiError>

Trait Implementations§

Source§

impl<Data: Debug, Meta: Debug> Debug for ApiResponse<Data, Meta>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de, Data, Meta> Deserialize<'de> for ApiResponse<Data, Meta>
where Data: Deserialize<'de>, Meta: Deserialize<'de>,

Source§

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<Data, Meta> From<ApiError> for ApiResponse<Data, Meta>

Source§

fn from(error: ApiError) -> Self

Converts to this type from the input type.
Source§

impl<Data, Meta> From<ApiResponse<Data, Meta>> for Result<Data, ApiError>

Source§

fn from(api_response: ApiResponse<Data, Meta>) -> Self

Converts to this type from the input type.
Source§

impl<Data, Meta> From<ApiResponse<Data, Meta>> for ApiResult<Data, Meta>

Source§

fn from(api_response: ApiResponse<Data, Meta>) -> Self

Converts to this type from the input type.
Source§

impl<Data, Meta> From<ErrorResponse<Meta>> for ApiResponse<Data, Meta>

Source§

fn from(value: ErrorResponse<Meta>) -> Self

Converts to this type from the input type.
Source§

impl<Data, Meta> From<Result<Data, ApiError>> for ApiResponse<Data, Meta>

Source§

fn from(result: Result<Data, ApiError>) -> Self

Converts to this type from the input type.
Source§

impl<Data, Meta> From<Result<SuccessResponse<Data, Meta>, ErrorResponse<Meta>>> for ApiResponse<Data, Meta>
where Meta: Default,

Source§

fn from(result: ApiResult<Data, Meta>) -> Self

Converts to this type from the input type.
Source§

impl<Data, Meta> From<SuccessResponse<Data, Meta>> for ApiResponse<Data, Meta>

Source§

fn from(value: SuccessResponse<Data, Meta>) -> Self

Converts to this type from the input type.
Source§

impl<Data, Meta> Serialize for ApiResponse<Data, Meta>
where Data: Serialize, Meta: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<Data, Meta> Freeze for ApiResponse<Data, Meta>
where Data: Freeze, Meta: Freeze,

§

impl<Data, Meta> !RefUnwindSafe for ApiResponse<Data, Meta>

§

impl<Data, Meta> Send for ApiResponse<Data, Meta>
where Data: Send, Meta: Send,

§

impl<Data, Meta> Sync for ApiResponse<Data, Meta>
where Data: Sync, Meta: Sync,

§

impl<Data, Meta> Unpin for ApiResponse<Data, Meta>
where Data: Unpin, Meta: Unpin,

§

impl<Data, Meta> !UnwindSafe for ApiResponse<Data, Meta>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<Data> ApiSuccessResponse for Data

Source§

fn api_response<Meta>(self, meta: Option<Meta>) -> ApiResponse<Self, Meta>

Source§

fn api_response_without_meta<Meta>(self) -> ApiResponse<Self, Meta>

Source§

fn api_response_with_meta<Meta>(self, meta: Meta) -> ApiResponse<Self, Meta>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,