diff options
Diffstat (limited to 'src/messages')
| -rw-r--r-- | src/messages/format_msg.rs | 37 | ||||
| -rw-r--r-- | src/messages/mod.rs | 2 |
2 files changed, 0 insertions, 39 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 diff --git a/src/messages/mod.rs b/src/messages/mod.rs index afc97c6..37a1cb7 100644 --- a/src/messages/mod.rs +++ b/src/messages/mod.rs @@ -1,10 +1,8 @@ use std::marker::Sized; -pub mod format_msg; pub mod callback; pub mod not_understood; -pub use self::format_msg::FormatMsg; pub use self::callback::Callback; pub use self::not_understood::NotUnderstood; |
