From 4117f797cec89927fe3363543b8c8b11a311b90c Mon Sep 17 00:00:00 2001 From: Kevin J Hoerr Date: Mon, 4 Nov 2019 14:06:58 -0500 Subject: Move FormatMsg to routes and add unit tests --- src/messages/format_msg.rs | 37 ------------------------------------- 1 file changed, 37 deletions(-) delete mode 100644 src/messages/format_msg.rs (limited to 'src/messages/format_msg.rs') 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 { - pub message: T, - pub code: StatusCode, -} - -impl FormatMsg { - /// 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 Responder for FormatMsg { - type Error = Error; - type Future = Result; - - 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 -- cgit