runs rustfmt, removes unused imports

This commit is contained in:
2019-06-18 15:49:10 +02:00
parent 9b3df58a08
commit f619f7229b
4 changed files with 33 additions and 37 deletions

View File

@@ -1,4 +1,5 @@
#[macro_use] extern crate diesel; #[macro_use]
extern crate diesel;
extern crate dotenv; extern crate dotenv;
use diesel::prelude::*; use diesel::prelude::*;
@@ -7,15 +8,13 @@ use std::env;
pub fn establish_connection() -> Result<SqliteConnection, String> { pub fn establish_connection() -> Result<SqliteConnection, String> {
dotenv().ok(); dotenv().ok();
let database_url = let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set !");
env::var("DATABASE_URL")
.expect("DATABASE_URL must be set !");
SqliteConnection::establish(&database_url) SqliteConnection::establish(&database_url)
.map_err(|e| format!("Error connecting to {} : {:?}", database_url, e)) .map_err(|e| format!("Error connecting to {} : {:?}", database_url, e))
} }
pub mod schema;
pub mod models; pub mod models;
pub mod schema;
pub fn list_players() -> Vec<models::Player> { pub fn list_players() -> Vec<models::Player> {
use schema::players::dsl::*; use schema::players::dsl::*;
@@ -25,15 +24,13 @@ pub fn list_players() -> Vec<models::Player> {
.expect("Error loading players") .expect("Error loading players")
} }
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
fn with_db<F>(f: F) -> () fn with_db<F>(f: F) -> ()
where F: Fn(&SqliteConnection) -> (), where
F: Fn(&SqliteConnection) -> (),
{ {
let conn = establish_connection().unwrap(); let conn = establish_connection().unwrap();
conn.test_transaction::<_, diesel::result::Error, _>(|| { conn.test_transaction::<_, diesel::result::Error, _>(|| {

View File

@@ -1,5 +1,5 @@
use crate::*;
use crate::schema::players; use crate::schema::players;
use crate::*;
#[derive(Queryable)] #[derive(Queryable)]
pub struct Player { pub struct Player {
@@ -23,13 +23,15 @@ pub struct NewPlayer<'a> {
} }
impl<'a> NewPlayer<'a> { impl<'a> NewPlayer<'a> {
fn new(name: &'a str, wealth: Option<(i32, i32, i32, i32)>) -> Self {
fn new(
name: &'a str,
wealth: Option<(i32,i32,i32,i32)>,
) -> Self {
let (cp, sp, gp, pp) = wealth.unwrap_or((0, 0, 0, 0)); let (cp, sp, gp, pp) = wealth.unwrap_or((0, 0, 0, 0));
NewPlayer { name, cp, sp, gp, pp } NewPlayer {
name,
cp,
sp,
gp,
pp,
}
} }
fn insert(&self) -> Result<(), ()> { fn insert(&self) -> Result<(), ()> {
@@ -39,8 +41,8 @@ impl<'a> NewPlayer<'a> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::tests;
use super::*; use super::*;
use crate::tests;
#[test] #[test]
fn new_player_only_with_name() { fn new_player_only_with_name() {

View File

@@ -30,8 +30,4 @@ table! {
joinable!(looted -> items (item_id)); joinable!(looted -> items (item_id));
joinable!(looted -> players (player_id)); joinable!(looted -> players (player_id));
allow_tables_to_appear_in_same_query!( allow_tables_to_appear_in_same_query!(items, looted, players,);
items,
looted,
players,
);

View File

@@ -1,12 +1,9 @@
extern crate lootalot_db;
extern crate actix_web; extern crate actix_web;
extern crate dotenv; extern crate dotenv;
extern crate lootalot_db;
use actix_web::{fs, server, App, HttpRequest, Result};
use std::env; use std::env;
use std::cell::RefCell;
use std::rc::Rc;
use actix_web::{server, App, Result, HttpRequest, fs };
fn main() { fn main() {
println!("Hello, world!"); println!("Hello, world!");
@@ -16,8 +13,12 @@ fn main() {
let www_root: String = env::var("WWW_ROOT").expect("WWW_ROOT must be set"); let www_root: String = env::var("WWW_ROOT").expect("WWW_ROOT must be set");
println!("serving files from: {}", &www_root); println!("serving files from: {}", &www_root);
server::new(move || { server::new(move || {
App::new() App::new().handler(
.handler("/", fs::StaticFiles::new(www_root.clone()).unwrap().index_file("index.html")) "/",
fs::StaticFiles::new(www_root.clone())
.unwrap()
.index_file("index.html"),
)
}) })
.bind("127.0.0.1:8088") .bind("127.0.0.1:8088")
.unwrap() .unwrap()