aboutsummaryrefslogtreecommitdiff
path: root/src/messages/format_msg.rs
diff options
context:
space:
mode:
authorKevin J Hoerr <kjhoerr@protonmail.com>2019-11-04 14:06:58 -0500
committerKevin J Hoerr <kjhoerr@protonmail.com>2019-11-04 14:06:58 -0500
commit4117f797cec89927fe3363543b8c8b11a311b90c (patch)
tree3f7320ee5a81a2e760c9f87991d63771633e5865 /src/messages/format_msg.rs
parent0c1dce106e0fb211cb52b2a780febd2a1b5f0a47 (diff)
downloadaugust-offensive-4117f797cec89927fe3363543b8c8b11a311b90c.tar.gz
august-offensive-4117f797cec89927fe3363543b8c8b11a311b90c.tar.bz2
august-offensive-4117f797cec89927fe3363543b8c8b11a311b90c.zip
Move FormatMsg to routes and add unit tests
Diffstat (limited to 'src/messages/format_msg.rs')
-rw-r--r--src/messages/format_msg.rs37
1 files changed, 0 insertions, 37 deletions
diff --git a/src/messages/format_msg.rs b/src/messages/format_msg.rs
deleted file mode 100644
index 34e4981..0000000
--- a/src/messages/format_msg.rs
+++ /dev/null
@@ -1,37 +0,0 @@
-use actix_web::{http::StatusCode, Error, HttpRequest, HttpResponse, Responder};
-use serde::Serialize;
-
-pub struct FormatMsg<T> {
- pub message: T,
- pub code: StatusCode,
-}
-
-impl<T> FormatMsg<T> {
- /// Deconstruct to an inner value
- pub fn into_inner(self) -> T {
- self.message
- }
-
- pub fn ok(message: T) -> Self {
- FormatMsg {
- message: message,
- code: StatusCode::OK,
- }
- }
-}
-
-impl<T: Serialize> Responder for FormatMsg<T> {
- type Error = Error;
- type Future = Result<HttpResponse, Error>;
-
- fn respond_to(self, _: &HttpRequest) -> Self::Future {
- let body = match serde_json::to_string(&self.message) {
- Ok(body) => body,
- Err(e) => return Err(e.into()),
- };
-
- Ok(HttpResponse::build(self.code)
- .content_type("application/json")
- .body(body))
- }
-} \ No newline at end of file