diff --git a/src/ear.rs b/src/ear.rs index 9b80e28..2195123 100644 --- a/src/ear.rs +++ b/src/ear.rs @@ -143,12 +143,14 @@ fn handle_post_request(request: Request, mut sender: Mouth) { } }; match database::add_favorite(mirabelid) { - Ok(result) => sender.send_ok( - format!("Favori inséré avec succès : {}", result.titre), - ), + Ok(result) => { + sender.send_ok(format!("Favori inséré avec succès : {}", result.titre)) + } Err(err) => match err { database::DatabaseError::NotFound => sender.send_not_found(format!("{}", err)), - database::DatabaseError::FoundDuplicate => sender.send_bad_request(format!("{}", err).as_str()), + database::DatabaseError::FoundDuplicate => { + sender.send_bad_request(format!("{}", err).as_str()) + } _ => sender.send_internal_error(format!("{}", err)), }, } diff --git a/src/mouth.rs b/src/mouth.rs index ee8594a..eb49f96 100644 --- a/src/mouth.rs +++ b/src/mouth.rs @@ -43,7 +43,10 @@ impl<'a> Mouth<'a> { } /// Send OK response to a client. - pub fn send_ok(&mut self, data: T) where T: Serialize { + pub fn send_ok(&mut self, data: T) + where + T: Serialize, + { self.send_data(Status::OK, serde_json::json!(data)); } @@ -58,19 +61,23 @@ impl<'a> Mouth<'a> { } else { data }; - self.send_data( - Status::BadRequest, - data, - ); + + self.send_data(Status::BadRequest, data); } /// Send InternalError response to a client. - pub fn send_internal_error(&mut self, data: T) where T: Serialize { + pub fn send_internal_error(&mut self, data: T) + where + T: Serialize, + { self.send_data(Status::InternalError, serde_json::json!(data)); } /// Send NotFound response to a client. - pub fn send_not_found(&mut self, data: T) where T: Serialize { + pub fn send_not_found(&mut self, data: T) + where + T: Serialize, + { self.send_data(Status::NotFound, serde_json::json!(data)); } }