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,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<SqliteConnection, String> {
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<models::Player> {
use schema::players::dsl::*;
@@ -25,18 +24,16 @@ pub fn list_players() -> Vec<models::Player> {
.expect("Error loading players")
}
#[cfg(test)]
mod tests {
use super::*;
fn with_db<F>(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(())
});

View File

@@ -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() {

View File

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

View File

@@ -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,8 +13,12 @@ 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()