Run rustfmt on everything

This commit is contained in:
AppleTheGolden
2020-05-27 20:51:28 +02:00
parent c49f0ede16
commit 91274267e5
11 changed files with 54 additions and 34 deletions

View File

@@ -1,11 +1,12 @@
use diesel::prelude::*;
use diesel::pg::PgConnection; use diesel::pg::PgConnection;
use diesel::prelude::*;
use dotenv::dotenv; use dotenv::dotenv;
use std::env; use std::env;
pub fn connect() -> PgConnection{ pub fn connect() -> PgConnection {
dotenv().ok(); dotenv().ok();
let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set!"); let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set!");
PgConnection::establish(&database_url).unwrap_or_else(|_| panic!("Error connecting to {}", database_url)) PgConnection::establish(&database_url)
.unwrap_or_else(|_| panic!("Error connecting to {}", database_url))
} }

View File

@@ -3,4 +3,4 @@ mod models;
pub use database::connect; pub use database::connect;
pub use models::Mod; pub use models::Mod;
pub use models::Version; pub use models::Version;

View File

@@ -10,7 +10,7 @@ pub struct Mod {
pub downloads: i32, pub downloads: i32,
pub categories: Vec<String>, pub categories: Vec<String>,
pub body_path: String, pub body_path: String,
pub icon_path: String pub icon_path: String,
} }
#[derive(Queryable)] #[derive(Queryable)]
@@ -20,10 +20,9 @@ pub struct Version {
pub title: String, pub title: String,
pub changelog_path: String, pub changelog_path: String,
pub files_path: Vec<String>, pub files_path: Vec<String>,
pub date_published: NaiveDate, pub date_published: NaiveDate,
pub author: String, pub author: String,
pub downloads: i32, pub downloads: i32,
pub dependencies: Vec<String>, pub dependencies: Vec<String>,
pub game_versions: Vec<String> pub game_versions: Vec<String>,
} }

View File

@@ -4,11 +4,28 @@ use handlebars::*;
pub struct ContainsHelper; pub struct ContainsHelper;
impl HelperDef for ContainsHelper { impl HelperDef for ContainsHelper {
fn call<'reg: 'rc, 'rc>(&self, h: &Helper<'reg, 'rc>, r: &'reg Handlebars<'_>, ctx: &'rc Context, rc: &mut RenderContext<'reg, 'rc>, out: &mut dyn Output) -> HelperResult { fn call<'reg: 'rc, 'rc>(
let array = h.param(0).map(|v| serde_json::from_value::<Vec<String>>(v.value().clone()).unwrap()).ok_or_else(|| RenderError::new("Parameter not found!"))?; &self,
let value = h.param(1).map(|v| v.value().as_str().unwrap()).ok_or_else(|| RenderError::new("Parameter not found!"))?; h: &Helper<'reg, 'rc>,
r: &'reg Handlebars<'_>,
ctx: &'rc Context,
rc: &mut RenderContext<'reg, 'rc>,
out: &mut dyn Output,
) -> HelperResult {
let array = h
.param(0)
.map(|v| serde_json::from_value::<Vec<String>>(v.value().clone()).unwrap())
.ok_or_else(|| RenderError::new("Parameter not found!"))?;
let value = h
.param(1)
.map(|v| v.value().as_str().unwrap())
.ok_or_else(|| RenderError::new("Parameter not found!"))?;
let tmpl = if array.contains(&String::from(value)) { h.template() } else { h.inverse() }; let tmpl = if array.contains(&String::from(value)) {
h.template()
} else {
h.inverse()
};
match tmpl { match tmpl {
Some(ref t) => t.render(r, ctx, rc, out), Some(ref t) => t.render(r, ctx, rc, out),

View File

@@ -5,7 +5,14 @@ use handlebars::*;
pub struct HumanFormatHelper; pub struct HumanFormatHelper;
impl HelperDef for HumanFormatHelper { impl HelperDef for HumanFormatHelper {
fn call<'reg: 'rc, 'rc>(&self, h: &Helper<'reg, 'rc>, _r: &'reg Handlebars<'_>, _ctx: &'rc Context, _rc: &mut RenderContext<'reg, 'rc>, out: &mut dyn Output) -> HelperResult { fn call<'reg: 'rc, 'rc>(
&self,
h: &Helper<'reg, 'rc>,
_r: &'reg Handlebars<'_>,
_ctx: &'rc Context,
_rc: &mut RenderContext<'reg, 'rc>,
out: &mut dyn Output,
) -> HelperResult {
let param = h.param(0).and_then(|v| v.value().as_f64()).unwrap_or(0.0); let param = h.param(0).and_then(|v| v.value().as_f64()).unwrap_or(0.0);
let mut formatted = human_format::Formatter::new().format(param); let mut formatted = human_format::Formatter::new().format(param);
@@ -15,4 +22,4 @@ impl HelperDef for HumanFormatHelper {
Ok(()) Ok(())
} }
} }

View File

@@ -2,4 +2,4 @@ mod contains;
mod format_human; mod format_human;
pub use contains::ContainsHelper; pub use contains::ContainsHelper;
pub use format_human::HumanFormatHelper; pub use format_human::HumanFormatHelper;

View File

@@ -4,14 +4,14 @@ extern crate serde_json;
#[macro_use] #[macro_use]
extern crate diesel; extern crate diesel;
use actix_files as fs;
use actix_web::{web, App, HttpServer}; use actix_web::{web, App, HttpServer};
use handlebars::*; use handlebars::*;
use actix_files as fs;
mod schema;
mod routes;
mod helpers;
mod database; mod database;
mod helpers;
mod routes;
mod schema;
#[actix_rt::main] #[actix_rt::main]
async fn main() -> std::io::Result<()> { async fn main() -> std::io::Result<()> {
@@ -39,8 +39,7 @@ async fn main() -> std::io::Result<()> {
.service(routes::search_get) .service(routes::search_get)
.service(routes::mod_editor_get) .service(routes::mod_editor_get)
}) })
.bind("127.0.0.1:8000")? .bind("127.0.0.1:8000")?
.run() .run()
.await .await
} }

View File

@@ -1,4 +1,4 @@
use actix_web::{web, HttpResponse, get}; use actix_web::{get, web, HttpResponse};
use handlebars::*; use handlebars::*;
#[get("/")] #[get("/")]
@@ -9,4 +9,4 @@ pub async fn index_get(hb: web::Data<Handlebars<'_>>) -> HttpResponse {
let body = hb.render("index", &data).unwrap(); let body = hb.render("index", &data).unwrap();
HttpResponse::Ok().body(body) HttpResponse::Ok().body(body)
} }

View File

@@ -1,11 +1,11 @@
mod search;
mod index; mod index;
mod mod_editor; mod mod_editor;
mod search;
pub use self::mod_editor::mod_editor_get; pub use self::mod_editor::mod_editor_get;
pub use self::search::index_mods;
pub use self::search::search_get; pub use self::search::search_get;
pub use self::search::search_post; pub use self::search::search_post;
pub use self::search::index_mods;
pub use self::index::index_get; pub use self::index::index_get;

View File

@@ -1,4 +1,4 @@
use actix_web::{web, HttpResponse, get}; use actix_web::{get, web, HttpResponse};
use handlebars::*; use handlebars::*;
#[get("modeditor")] #[get("modeditor")]
@@ -9,4 +9,4 @@ pub async fn mod_editor_get(hb: web::Data<Handlebars<'_>>) -> HttpResponse {
let body = hb.render("mod_editor", &data).unwrap(); let body = hb.render("mod_editor", &data).unwrap();
HttpResponse::Ok().body(body) HttpResponse::Ok().body(body)
} }

View File

@@ -27,7 +27,4 @@ table! {
} }
} }
allow_tables_to_appear_in_same_query!( allow_tables_to_appear_in_same_query!(mods, versions,);
mods,
versions,
);