From 6de079b2792ad95fcbb9c7883b0cf9eb7ae90058 Mon Sep 17 00:00:00 2001 From: ElnuDev Date: Sat, 30 Jul 2022 13:19:30 -0700 Subject: [PATCH] cargo fmt --- src/main.rs | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/src/main.rs b/src/main.rs index f397f37..f1d3e8c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -37,19 +37,20 @@ enum Error { impl Error { fn to_http_response(&self) -> HttpResponse { match self { - Self::InvalidOrigin | - Self::InvalidBody | - Self::InvalidUrl | - Self::InvalidFields | - Self::InvalidContentId | - Self::InvalidParent | - Self::EmailRequired | - Self::NameRequired => HttpResponse::BadRequest(), - Self::DatabaseAccessError | - Self::DatabaseInternalError | - Self::SanitizationError | - Self::PageFetchError => HttpResponse::InternalServerError(), - }.reason(match self { + Self::InvalidOrigin + | Self::InvalidBody + | Self::InvalidUrl + | Self::InvalidFields + | Self::InvalidContentId + | Self::InvalidParent + | Self::EmailRequired + | Self::NameRequired => HttpResponse::BadRequest(), + Self::DatabaseAccessError + | Self::DatabaseInternalError + | Self::SanitizationError + | Self::PageFetchError => HttpResponse::InternalServerError(), + } + .reason(match self { Self::InvalidOrigin => "invalid request origin", Self::InvalidBody => "invalid request body", Self::InvalidUrl => "invalid request url", @@ -62,15 +63,13 @@ impl Error { Self::DatabaseInternalError => "database internal error", Self::SanitizationError => "comment sanitization error", Self::PageFetchError => "page fetch error", - }).finish() + }) + .finish() } } impl AppState { - fn get_db<'a>( - &'a self, - origin: Option, - ) -> Result, Error> { + fn get_db<'a>(&'a self, origin: Option) -> Result, Error> { let origin = match origin { Some(origin) => origin, None => return Err(Error::InvalidOrigin), @@ -141,7 +140,9 @@ async fn _get_comments( Err(_) => return Err(Error::DatabaseInternalError), }, ) - }).await { + }) + .await + { Ok(result) => result, Err(_) => Err(Error::DatabaseAccessError), } @@ -221,7 +222,7 @@ async fn _post_comment( Ok(page_data_option) => match page_data_option { Some(page_data) => { if page_data.content_id != comment.content_id { - return Err(Error::InvalidContentId) + return Err(Error::InvalidContentId); } } None => return Err(Error::InvalidUrl), // e.g. 404 @@ -247,7 +248,7 @@ async fn _post_comment( break; } } - }, + } Err(_) => { return Err(Error::DatabaseInternalError); }