From e2003442e2037ba85d14c2b942db63b451c4dc9f Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Tue, 12 Oct 2021 17:10:51 +0200 Subject: [PATCH] Main now ignores unused mut --- src/db/posts.rs | 2 +- src/main.rs | 25 +++++++++++++++++++------ src/posts.rs | 12 ++++++++++-- src/schema.rs | 7 +------ 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/src/db/posts.rs b/src/db/posts.rs index 5a9e1ee..523945d 100644 --- a/src/db/posts.rs +++ b/src/db/posts.rs @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize}; use uuid::Uuid; use crate::{ - errors::{RbError, RbResult, RbOption}, + errors::{RbError, RbOption, RbResult}, schema::{posts, posts::dsl::*}, }; diff --git a/src/main.rs b/src/main.rs index e644965..2a474cc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,16 +12,14 @@ use figment::{ providers::{Env, Format, Yaml}, Figment, }; +#[cfg(any(feature = "web", feature = "docs"))] +use rocket::fs; use rocket::{ fairing::AdHoc, http::Status, serde::json::{json, Value}, Build, Orbit, Request, Rocket, }; - -#[cfg(any(feature = "web", feature="docs"))] -use rocket::fs; - use rocket_sync_db_pools::database; use serde::{Deserialize, Serialize}; @@ -98,6 +96,9 @@ fn rocket() -> _ .merge(Yaml::file("Rb.yaml").nested()) .merge(Env::prefixed("RB_").global()); + // This mut is necessary when the "docs" or "web" feature is enabled, as these further modify + // the instance variable + #[allow(unused_mut)] let mut instance = rocket::custom(figment) .attach(RbDbConn::fairing()) .attach(AdHoc::try_on_ignite( @@ -121,12 +122,24 @@ fn rocket() -> _ // It's weird that this is allowed, but the line on its own isn't #[cfg(feature = "web")] { - instance = instance.mount("/", fs::FileServer::new("/var/www/html/web", fs::Options::Index | fs::Options::NormalizeDirs)); + instance = instance.mount( + "/", + fs::FileServer::new( + "/var/www/html/web", + fs::Options::Index | fs::Options::NormalizeDirs, + ), + ); } #[cfg(feature = "docs")] { - instance = instance.mount("/docs", fs::FileServer::new("/var/www/html/docs", fs::Options::Index | fs::Options::NormalizeDirs)); + instance = instance.mount( + "/docs", + fs::FileServer::new( + "/var/www/html/docs", + fs::Options::Index | fs::Options::NormalizeDirs, + ), + ); } instance diff --git a/src/posts.rs b/src/posts.rs index cb11582..4c95681 100644 --- a/src/posts.rs +++ b/src/posts.rs @@ -1,6 +1,11 @@ use rocket::serde::json::Json; -use crate::{db, errors::RbResult, errors::RbOption, guards::Admin, RbDbConn}; +use crate::{ + db, + errors::{RbOption, RbResult}, + guards::Admin, + RbDbConn, +}; #[get("/?&")] pub async fn get(conn: RbDbConn, offset: u32, limit: u32) -> RbResult>> @@ -26,7 +31,10 @@ pub async fn create( #[get("/")] pub async fn find(conn: RbDbConn, id: uuid::Uuid) -> RbOption> { - Ok(conn.run(move |c| db::posts::find(c, &id)).await?.and_then(|p| Some(Json(p)))) + Ok(conn + .run(move |c| db::posts::find(c, &id)) + .await? + .and_then(|p| Some(Json(p)))) } #[patch("/", data = "")] diff --git a/src/schema.rs b/src/schema.rs index d8b585e..195ff9f 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -41,9 +41,4 @@ table! { joinable!(posts -> sections (section_id)); joinable!(refresh_tokens -> users (user_id)); -allow_tables_to_appear_in_same_query!( - posts, - refresh_tokens, - sections, - users, -); +allow_tables_to_appear_in_same_query!(posts, refresh_tokens, sections, users,);