You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
539 B

  1. use serde::{Deserialize, Serialize};
  2. #[derive(PartialEq, Debug, Clone, Serialize, Deserialize, new)]
  3. pub struct ApiResponse<T> {
  4. success: bool,
  5. response: T,
  6. }
  7. impl<T: Serialize> ApiResponse<T> {
  8. pub fn is_success(&self) -> bool {
  9. self.success
  10. }
  11. pub fn response(&self) -> &T {
  12. &self.response
  13. }
  14. pub fn successful(response: T) -> ApiResponse<T> {
  15. ApiResponse::new(true, response)
  16. }
  17. pub fn failure(response: T) -> ApiResponse<T> {
  18. ApiResponse::new(false, response)
  19. }
  20. }