diff --git a/lootalot_db/src/lib.rs b/lootalot_db/src/lib.rs index 2ea9807..ffc8932 100644 --- a/lootalot_db/src/lib.rs +++ b/lootalot_db/src/lib.rs @@ -1,5 +1,6 @@ -#[macro_use] extern crate diesel; - extern crate dotenv; +#[macro_use] +extern crate diesel; +extern crate dotenv; use diesel::prelude::*; use dotenv::dotenv; @@ -7,15 +8,13 @@ use std::env; pub fn establish_connection() -> Result { 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 !"); SqliteConnection::establish(&database_url) .map_err(|e| format!("Error connecting to {} : {:?}", database_url, e)) } -pub mod schema; pub mod models; +pub mod schema; pub fn list_players() -> Vec { use schema::players::dsl::*; @@ -25,18 +24,16 @@ pub fn list_players() -> Vec { .expect("Error loading players") } - - - #[cfg(test)] mod tests { use super::*; fn with_db(f: F) -> () - where F: Fn(&SqliteConnection) -> (), + where + F: Fn(&SqliteConnection) -> (), { let conn = establish_connection().unwrap(); - conn.test_transaction::<_,diesel::result::Error,_>(|| { + conn.test_transaction::<_, diesel::result::Error, _>(|| { f(&conn); Ok(()) }); diff --git a/lootalot_db/src/models.rs b/lootalot_db/src/models.rs index 93c9977..16a1fc3 100644 --- a/lootalot_db/src/models.rs +++ b/lootalot_db/src/models.rs @@ -1,5 +1,5 @@ -use crate::*; use crate::schema::players; +use crate::*; #[derive(Queryable)] pub struct Player { @@ -13,7 +13,7 @@ pub struct Player { } #[derive(Insertable)] -#[table_name="players"] +#[table_name = "players"] pub struct NewPlayer<'a> { name: &'a str, cp: i32, @@ -23,24 +23,26 @@ pub struct NewPlayer<'a> { } impl<'a> NewPlayer<'a> { - - fn new( - name: &'a str, - wealth: Option<(i32,i32,i32,i32)>, - ) -> Self { - let (cp,sp,gp,pp) = wealth.unwrap_or((0,0,0,0)); - NewPlayer { name, cp, sp, gp, pp } + fn new(name: &'a str, wealth: Option<(i32, i32, i32, i32)>) -> Self { + let (cp, sp, gp, pp) = wealth.unwrap_or((0, 0, 0, 0)); + NewPlayer { + name, + cp, + sp, + gp, + pp, + } } - fn insert(&self) -> Result<(),()> { + fn insert(&self) -> Result<(), ()> { Err(()) } } #[cfg(test)] mod tests { - use crate::tests; use super::*; + use crate::tests; #[test] fn new_player_only_with_name() { diff --git a/lootalot_db/src/schema.rs b/lootalot_db/src/schema.rs index f5a1efa..b7c9058 100644 --- a/lootalot_db/src/schema.rs +++ b/lootalot_db/src/schema.rs @@ -30,8 +30,4 @@ table! { joinable!(looted -> items (item_id)); joinable!(looted -> players (player_id)); -allow_tables_to_appear_in_same_query!( - items, - looted, - players, -); +allow_tables_to_appear_in_same_query!(items, looted, players,); diff --git a/src/main.rs b/src/main.rs index dfeba02..2d428a0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,12 +1,9 @@ -extern crate lootalot_db; extern crate actix_web; extern crate dotenv; +extern crate lootalot_db; +use actix_web::{fs, server, App, HttpRequest, Result}; use std::env; -use std::cell::RefCell; -use std::rc::Rc; -use actix_web::{server, App, Result, HttpRequest, fs }; - fn main() { println!("Hello, world!"); @@ -16,10 +13,14 @@ fn main() { let www_root: String = env::var("WWW_ROOT").expect("WWW_ROOT must be set"); println!("serving files from: {}", &www_root); server::new(move || { - App::new() - .handler("/", fs::StaticFiles::new(www_root.clone()).unwrap().index_file("index.html")) + App::new().handler( + "/", + fs::StaticFiles::new(www_root.clone()) + .unwrap() + .index_file("index.html"), + ) }) - .bind("127.0.0.1:8088") - .unwrap() - .run(); + .bind("127.0.0.1:8088") + .unwrap() + .run(); }