Main now ignores unused mut

develop
Jef Roosens 2021-10-12 17:10:51 +02:00
parent 19a21b8cdf
commit e2003442e2
Signed by: Jef Roosens
GPG Key ID: 955C0660072F691F
4 changed files with 31 additions and 15 deletions

View File

@ -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::*},
};

View File

@ -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

View File

@ -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("/?<offset>&<limit>")]
pub async fn get(conn: RbDbConn, offset: u32, limit: u32) -> RbResult<Json<Vec<db::Post>>>
@ -26,7 +31,10 @@ pub async fn create(
#[get("/<id>")]
pub async fn find(conn: RbDbConn, id: uuid::Uuid) -> RbOption<Json<db::Post>>
{
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("/<id>", data = "<patch_post>")]

View File

@ -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,);