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 {
ConfigPath(
dirs::config_dir()
.unwrap_or(Path::new(".config").to_path_buf())
.unwrap_or_else(|| Path::new(".config").to_path_buf())
.join("gmarche"),
)
}

View File

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

View File

@ -1,9 +1,9 @@
use sled::{Db, Tree};
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 db: Db,

View File

@ -1,7 +1,7 @@
use std::path::Path;
pub const STATIC_DIR: &'static str = "static";
static STATIC_FILES: &'static [(&str, &[u8])] = &[
pub const STATIC_DIR: &str = "static";
static STATIC_FILES: &[(&str, &[u8])] = &[
("style1.css", include_bytes!("../static/style1.css")),
("standgm.png", include_bytes!("../static/standgm.png")),
("banner.jpg", include_bytes!("../static/banner.jpg")),
@ -21,7 +21,7 @@ pub fn init_static_files(dir: &Path) {
let file_path = dir.join(file);
if !file_path.is_file() {
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 std::path::Path;
const TEMPLATES_DIR: &'static str = "templates";
static TEMPLATE_FILES: &'static [(&str, &str)] = &[
const TEMPLATES_DIR: &str = "templates";
static TEMPLATE_FILES: &[(&str, &str)] = &[
("index.html", include_str!("../templates/index.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);
if !file_path.is_file() {
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,
std::str::from_utf8(
&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();
}