From 245fcbcf1e8e786aa215acd70ae6c21013f124ae Mon Sep 17 00:00:00 2001 From: ElnuDev Date: Tue, 20 Jun 2023 13:47:29 -0700 Subject: [PATCH] cargo fmt --- src/i18n.rs | 36 +++++++++++++++++++++++++----------- src/main.rs | 17 ++++++++++------- src/models/settings.rs | 2 +- src/models/user/mod.rs | 4 ++-- src/routes/get_challenge.rs | 8 ++++++-- 5 files changed, 44 insertions(+), 23 deletions(-) diff --git a/src/i18n.rs b/src/i18n.rs index f05688e..43c5e99 100644 --- a/src/i18n.rs +++ b/src/i18n.rs @@ -1,6 +1,11 @@ -use std::{collections::HashMap, fs::{self, File}, io::BufReader, process::Command}; use derive_more::From; use rocket_dyn_templates::tera::{self, Value}; +use std::{ + collections::HashMap, + fs::{self, File}, + io::BufReader, + process::Command, +}; use gettext::Catalog; @@ -18,7 +23,12 @@ pub fn load_catalogs() -> Result, LoadCatalogsError> { for file in fs::read_dir("i18n")? { let file = file?; let path = file.path(); - if !file.file_type()?.is_file() || !path.extension().map(|extension| extension.eq("po")).unwrap_or(false) { + if !file.file_type()?.is_file() + || !path + .extension() + .map(|extension| extension.eq("po")) + .unwrap_or(false) + { continue; } let language_code = path @@ -33,7 +43,10 @@ pub fn load_catalogs() -> Result, LoadCatalogsError> { .arg("-o") .arg(&mo_file_path) .output()?; - catalogs.insert(language_code, Catalog::parse(BufReader::new(File::open(mo_file_path)?))?); + catalogs.insert( + language_code, + Catalog::parse(BufReader::new(File::open(mo_file_path)?))?, + ); } if !catalogs.contains_key(DEFAULT) { return Err(LoadCatalogsError::MissingDefaultLanguage); @@ -41,15 +54,16 @@ pub fn load_catalogs() -> Result, LoadCatalogsError> { Ok(catalogs) } -pub fn i18n_filter(value: &Value, _args: &HashMap, catalogs: &HashMap) -> tera::Result { - let key = value.as_str().ok_or_else(|| { - tera::Error::msg("The translation key must be a string") - })?; +pub fn i18n_filter( + value: &Value, + _args: &HashMap, + catalogs: &HashMap, +) -> tera::Result { + let key = value + .as_str() + .ok_or_else(|| tera::Error::msg("The translation key must be a string"))?; - let translation = catalogs - .get(DEFAULT) - .expect("Missing catalog") - .gettext(key); + let translation = catalogs.get(DEFAULT).expect("Missing catalog").gettext(key); Ok(Value::String(translation.to_owned())) } diff --git a/src/main.rs b/src/main.rs index 6eeaacd..b547586 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,9 +3,9 @@ extern crate rocket; use poise::serenity_prelude::Http; use rocket::fs::{relative, FileServer}; -use rocket_dyn_templates::{Template, tera}; +use rocket_dyn_templates::{tera, Template}; use sass_rocket_fairing::SassFairing; -use std::{env, collections::HashMap}; +use std::{collections::HashMap, env}; mod models; use models::Settings; @@ -18,7 +18,7 @@ mod routes; use routes::*; mod i18n; -use i18n::{load_catalogs, i18n_filter}; +use i18n::{i18n_filter, load_catalogs}; mod prelude; @@ -46,9 +46,12 @@ async fn rocket() -> _ { .attach(Template::custom(|engines| { use tera::Value; let catalogs = load_catalogs().unwrap(); - engines.tera.register_filter("i18n", move |value: &Value, args: &HashMap| { - i18n_filter(value, args, &catalogs) - }) + engines.tera.register_filter( + "i18n", + move |value: &Value, args: &HashMap| { + i18n_filter(value, args, &catalogs) + }, + ) })) .attach(SassFairing::default()) -} \ No newline at end of file +} diff --git a/src/models/settings.rs b/src/models/settings.rs index a34ea9a..2ac577b 100644 --- a/src/models/settings.rs +++ b/src/models/settings.rs @@ -54,4 +54,4 @@ impl Guild { self.name = Some(server.name); Ok(()) } -} \ No newline at end of file +} diff --git a/src/models/user/mod.rs b/src/models/user/mod.rs index 6e20014..37bca84 100644 --- a/src/models/user/mod.rs +++ b/src/models/user/mod.rs @@ -6,7 +6,7 @@ mod tests; use chrono::Utc; use derive_more::From; use reqwest::StatusCode; -use rocket::http::{CookieJar, Cookie}; +use rocket::http::{Cookie, CookieJar}; use serial::*; use serde::Deserialize; @@ -113,4 +113,4 @@ pub enum GetUserError { fn parse_cookie_value(cookies: &CookieJar<'_>, name: &str) -> Option { cookies.get_private(name)?.value().parse().ok() -} \ No newline at end of file +} diff --git a/src/routes/get_challenge.rs b/src/routes/get_challenge.rs index bbb94a3..565a51e 100644 --- a/src/routes/get_challenge.rs +++ b/src/routes/get_challenge.rs @@ -3,10 +3,14 @@ use std::ops::Deref; use rocket::{http::CookieJar, State}; use rocket_dyn_templates::{context, Template}; -use crate::models::{Challenge, User, Settings}; +use crate::models::{Challenge, Settings, User}; #[get("/")] -pub async fn get_challenge(challenge: u32, cookies: &CookieJar<'_>, settings: &State) -> Template { +pub async fn get_challenge( + challenge: u32, + cookies: &CookieJar<'_>, + settings: &State, +) -> Template { Template::render( "index", context! {