Clean code

This commit is contained in:
Pascal Engélibert 2020-12-08 11:05:59 +01:00
parent ade564460f
commit 2eafbaad41
5 changed files with 12 additions and 12 deletions

View File

@ -11,7 +11,7 @@ impl Default for ConfigPath {
fn default() -> ConfigPath { fn default() -> ConfigPath {
ConfigPath( ConfigPath(
dirs::config_dir() dirs::config_dir()
.unwrap_or(Path::new(".config").to_path_buf()) .unwrap_or_else(|| Path::new(".config").to_path_buf())
.join("gmarche"), .join("gmarche"),
) )
} }

View File

@ -4,7 +4,7 @@ use std::{
path::Path, path::Path,
}; };
const CONFIG_FILE: &'static str = "config.json"; const CONFIG_FILE: &str = "config.json";
#[derive(Deserialize, Serialize)] #[derive(Deserialize, Serialize)]
pub struct Config { pub struct Config {

View File

@ -1,9 +1,9 @@
use sled::{Db, Tree}; use sled::{Db, Tree};
use std::path::Path; use std::path::Path;
const DB_DIR: &'static str = "db"; const DB_DIR: &str = "db";
const DB_NAME_ADS: &'static str = "ads"; const DB_NAME_ADS: &str = "ads";
pub struct Dbs { pub struct Dbs {
pub db: Db, pub db: Db,

View File

@ -1,7 +1,7 @@
use std::path::Path; use std::path::Path;
pub const STATIC_DIR: &'static str = "static"; pub const STATIC_DIR: &str = "static";
static STATIC_FILES: &'static [(&str, &[u8])] = &[ static STATIC_FILES: &[(&str, &[u8])] = &[
("style1.css", include_bytes!("../static/style1.css")), ("style1.css", include_bytes!("../static/style1.css")),
("standgm.png", include_bytes!("../static/standgm.png")), ("standgm.png", include_bytes!("../static/standgm.png")),
("banner.jpg", include_bytes!("../static/banner.jpg")), ("banner.jpg", include_bytes!("../static/banner.jpg")),
@ -21,7 +21,7 @@ pub fn init_static_files(dir: &Path) {
let file_path = dir.join(file); let file_path = dir.join(file);
if !file_path.is_file() { if !file_path.is_file() {
std::fs::write(file_path, default) std::fs::write(file_path, default)
.expect(&format!("Cannot write template file {}", file)); .unwrap_or_else(|_| panic!("Cannot write template file {}", file));
} }
} }
} }

View File

@ -1,8 +1,8 @@
use handlebars::Handlebars; use handlebars::Handlebars;
use std::path::Path; use std::path::Path;
const TEMPLATES_DIR: &'static str = "templates"; const TEMPLATES_DIR: &str = "templates";
static TEMPLATE_FILES: &'static [(&str, &str)] = &[ static TEMPLATE_FILES: &[(&str, &str)] = &[
("index.html", include_str!("../templates/index.html")), ("index.html", include_str!("../templates/index.html")),
("admin.html", include_str!("../templates/admin.html")), ("admin.html", include_str!("../templates/admin.html")),
( (
@ -23,7 +23,7 @@ pub fn load_templates<'reg>(dir: &Path) -> Templates<'reg> {
let file_path = dir.join(file); let file_path = dir.join(file);
if !file_path.is_file() { if !file_path.is_file() {
std::fs::write(file_path, default) std::fs::write(file_path, default)
.expect(&format!("Cannot write template file {}", file)); .unwrap_or_else(|_| panic!("Cannot write template file {}", file));
} }
} }
@ -33,9 +33,9 @@ pub fn load_templates<'reg>(dir: &Path) -> Templates<'reg> {
file, file,
std::str::from_utf8( std::str::from_utf8(
&std::fs::read(dir.join(file)) &std::fs::read(dir.join(file))
.expect(&format!("Cannot read template file`{}`", file)), .unwrap_or_else(|_| panic!("Cannot read template file`{}`", file)),
) )
.expect(&format!("Bad encoding in template file `{}`", file)), .unwrap_or_else(|_| panic!("Bad encoding in template file `{}`", file)),
) )
.unwrap(); .unwrap();
} }