foxtive_ntex/http/response/
ext.rs1use crate::contracts::ResponseCodeContract;
2use crate::http::HttpResult;
3use ntex::web::HttpResponse;
4
5pub trait ResultResponseExt {
6 fn send_result<C: ResponseCodeContract>(self, code: C) -> HttpResult;
7
8 fn send_result_msg<C: ResponseCodeContract>(self, code: C, msg: &str) -> HttpResult;
9}
10
11pub trait AppMessageExt {
12 fn respond(self) -> HttpResult;
13}
14
15pub trait ResponderExt {
16 fn respond_code<C: ResponseCodeContract>(self, msg: &str, code: C) -> HttpResult;
17
18 fn respond_msg(self, suc: &str) -> HttpResult;
19
20 fn respond(self) -> HttpResult;
21
22 fn respond_undecorated(self) -> HttpResult;
23
24 fn respond_undecorated_code(self, code: impl ResponseCodeContract) -> HttpResult;
25}
26
27pub trait StructResponseExt: Sized {
28 fn into_response(self) -> HttpResponse;
29
30 fn respond_code<C: ResponseCodeContract>(self, code: C, msg: &str) -> HttpResult;
31
32 fn respond_msg(self, msg: &str) -> HttpResult;
33
34 fn respond(self) -> HttpResult;
35
36 fn respond_undecorated(self) -> HttpResult;
37
38 fn respond_undecorated_code(self, code: impl ResponseCodeContract) -> HttpResult;
39}
40
41pub trait OptionResultResponseExt<T> {
42 fn is_empty(&self) -> bool;
43
44 fn is_error(&self) -> bool;
45
46 fn is_error_or_empty(&self) -> bool;
47
48 fn send_response<C: ResponseCodeContract>(self, code: C, msg: &str) -> HttpResult;
49}
50
51pub trait IntoHttpResultExt {
52 fn http_result(self) -> HttpResult;
53}