Skip to main content

foxtive_ntex/http/response/
struct.rs

1use crate::contracts::ResponseCodeContract;
2use crate::enums::ResponseCode;
3use crate::http::HttpResult;
4use crate::http::responder::Responder;
5use crate::http::response::ext::StructResponseExt;
6use ntex::web::HttpResponse;
7use serde::Serialize;
8
9impl<T: Serialize> StructResponseExt for T {
10    fn into_response(self) -> HttpResponse {
11        Responder::send(self, ResponseCode::Ok)
12    }
13
14    fn respond_code<C: ResponseCodeContract>(self, code: C, msg: &str) -> HttpResult {
15        Ok(Responder::send_msg(self, code, msg))
16    }
17
18    fn respond_msg(self, msg: &str) -> HttpResult {
19        Ok(Responder::send_msg(self, ResponseCode::Ok, msg))
20    }
21
22    fn respond(self) -> HttpResult {
23        Ok(Responder::send(self, ResponseCode::Ok))
24    }
25
26    fn respond_undecorated(self) -> HttpResult {
27        self.respond_undecorated_code(ResponseCode::Ok)
28    }
29
30    fn respond_undecorated_code(self, code: impl ResponseCodeContract) -> HttpResult {
31        Ok(HttpResponse::build(code.status()).json(&self))
32    }
33}