diff --git a/pagetop/src/app/application.rs b/pagetop/src/app/application.rs index d1a56ce4..aa49adcb 100644 --- a/pagetop/src/app/application.rs +++ b/pagetop/src/app/application.rs @@ -3,7 +3,7 @@ use crate::config::SETTINGS; use crate::core::{module, theme}; use crate::html::Markup; use crate::response::page::ResultPage; -use crate::{base, trace, Lazy}; +use crate::{base, trace, LazyStatic}; use actix_web::dev::Server; use std::io::Error; @@ -18,14 +18,14 @@ impl Application { super::banner::print_on_startup(); // Inicia registro de trazas y eventos. - Lazy::force(&super::tracing::TRACING); + LazyStatic::force(&super::tracing::TRACING); // Valida el identificador de idioma. - Lazy::force(&super::locale::LANGID); + LazyStatic::force(&super::locale::LANGID); // Conecta con la base de datos (opcional). #[cfg(any(feature = "mysql", feature = "postgres", feature = "sqlite"))] - Lazy::force(&super::db::DBCONN); + LazyStatic::force(&super::db::DBCONN); // Habilita los módulos predeterminados. module::all::enable_modules(vec![&base::module::homepage::DefaultHomePage]); diff --git a/pagetop/src/app/banner/figfont.rs b/pagetop/src/app/banner/figfont.rs index 51be8ae9..d92fe35a 100644 --- a/pagetop/src/app/banner/figfont.rs +++ b/pagetop/src/app/banner/figfont.rs @@ -1,9 +1,9 @@ use crate::config::SETTINGS; -use crate::Lazy; +use crate::LazyStatic; use figlet_rs::FIGfont; -pub static FIGFONT: Lazy = Lazy::new(|| { +pub static FIGFONT: LazyStatic = LazyStatic::new(|| { let slant = include_str!("slant.flf"); let small = include_str!("small.flf"); let speed = include_str!("speed.flf"); diff --git a/pagetop/src/app/db.rs b/pagetop/src/app/db.rs index 23818424..98f96e47 100644 --- a/pagetop/src/app/db.rs +++ b/pagetop/src/app/db.rs @@ -1,11 +1,11 @@ use crate::config::SETTINGS; use crate::db::*; -use crate::{run_now, trace, Lazy}; +use crate::{run_now, trace, LazyStatic}; use sea_orm::{ConnectOptions, ConnectionTrait, Database, DatabaseBackend, Statement}; use tracing_unwrap::ResultExt; -pub static DBCONN: Lazy = Lazy::new(|| { +pub static DBCONN: LazyStatic = LazyStatic::new(|| { trace::info!( "Connecting to database \"{}\" using a pool of {} connections", &SETTINGS.database.db_name, @@ -61,7 +61,7 @@ pub static DBCONN: Lazy = Lazy::new(|| { .expect_or_log("Failed to connect to database") }); -static DBBACKEND: Lazy = Lazy::new(|| DBCONN.get_database_backend()); +static DBBACKEND: LazyStatic = LazyStatic::new(|| DBCONN.get_database_backend()); pub async fn query(stmt: &mut Q) -> Result, DbErr> { DBCONN diff --git a/pagetop/src/app/locale.rs b/pagetop/src/app/locale.rs index af7a57c8..5354ffdb 100644 --- a/pagetop/src/app/locale.rs +++ b/pagetop/src/app/locale.rs @@ -1,22 +1,24 @@ use crate::config::SETTINGS; -use crate::{trace, Lazy}; +use crate::{trace, LazyStatic}; use unic_langid::LanguageIdentifier; /// Almacena el Identificador de Idioma Unicode ([Unicode Language Identifier] /// (https://unicode.org/reports/tr35/tr35.html#Unicode_language_identifier)) de /// la aplicación, obtenido de `SETTINGS.app.language`. -pub static LANGID: Lazy = Lazy::new(|| match SETTINGS.app.language.parse() { - Ok(language) => language, - Err(_) => { - trace::warn!( - "{}, {} \"{}\"! {}, {}", - "Failed to parse language", - "unrecognized Unicode Language Identifier", - SETTINGS.app.language, - "Using \"en-US\"", - "check the settings file", - ); - "en-US".parse().unwrap() +pub static LANGID: LazyStatic = LazyStatic::new(|| + match SETTINGS.app.language.parse() { + Ok(language) => language, + Err(_) => { + trace::warn!( + "{}, {} \"{}\"! {}, {}", + "Failed to parse language", + "unrecognized Unicode Language Identifier", + SETTINGS.app.language, + "Using \"en-US\"", + "check the settings file", + ); + "en-US".parse().unwrap() + } } -}); +); diff --git a/pagetop/src/app/tracing.rs b/pagetop/src/app/tracing.rs index d7c8e071..4282cb7d 100644 --- a/pagetop/src/app/tracing.rs +++ b/pagetop/src/app/tracing.rs @@ -1,5 +1,5 @@ use crate::config::SETTINGS; -use crate::Lazy; +use crate::LazyStatic; use tracing_appender::non_blocking::WorkerGuard; use tracing_subscriber::EnvFilter; @@ -17,7 +17,7 @@ use tracing_subscriber::EnvFilter; /// `Lazy` se garantiza que todos los registros almacenados se /// enviarán antes de terminar la ejecución. -pub static TRACING: Lazy = Lazy::new(|| { +pub static TRACING: LazyStatic = LazyStatic::new(|| { let env_filter = EnvFilter::try_new(&SETTINGS.log.tracing).unwrap_or_else(|_| EnvFilter::new("Info")); let rolling = SETTINGS.log.rolling.to_lowercase(); diff --git a/pagetop/src/config.rs b/pagetop/src/config.rs index cc5d3c3b..7c8b32d8 100644 --- a/pagetop/src/config.rs +++ b/pagetop/src/config.rs @@ -1,4 +1,4 @@ -use crate::Lazy; +use crate::LazyStatic; use config_rs::{Config, File}; use serde::Deserialize; @@ -12,7 +12,7 @@ const CONFIG_DIR: &str = "config"; /// los archivos de configuración. Con [`config_map`] se asignarán los ajustes /// globales ([`SETTINGS`]); y se podrán asignar los ajustes específicos de la /// aplicación, o también de un tema, módulo o componente. -pub static CONFIG: Lazy = Lazy::new(|| { +pub static CONFIG: LazyStatic = LazyStatic::new(|| { // Establece el modo de ejecución según el valor de la variable de entorno // PAGETOP_RUN_MODE. Asume "default" por defecto. let run_mode = env::var("PAGETOP_RUN_MODE").unwrap_or_else(|_| "default".into()); @@ -48,7 +48,7 @@ macro_rules! config_map { $crate::doc_comment! { concat!($doc), - pub static $SETTINGS: $crate::Lazy<$Type> = $crate::Lazy::new(|| { + pub static $SETTINGS: $crate::LazyStatic<$Type> = $crate::LazyStatic::new(|| { let mut settings = $crate::config::CONFIG.clone(); $( settings.set_default($key, $value).unwrap(); diff --git a/pagetop/src/core/component/all.rs b/pagetop/src/core/component/all.rs index 4309c3a7..74873a46 100644 --- a/pagetop/src/core/component/all.rs +++ b/pagetop/src/core/component/all.rs @@ -1,11 +1,12 @@ use super::{ComponentTrait, ComponentsBundle}; -use crate::Lazy; +use crate::LazyStatic; use std::collections::HashMap; use std::sync::RwLock; -static COMPONENTS: Lazy>> = - Lazy::new(|| RwLock::new(HashMap::new())); +static COMPONENTS: LazyStatic>> = LazyStatic::new(|| + RwLock::new(HashMap::new()) +); pub fn add_component_to(region: &'static str, component: impl ComponentTrait) { let mut hmap = COMPONENTS.write().unwrap(); diff --git a/pagetop/src/core/component/context.rs b/pagetop/src/core/component/context.rs index e7aa814c..0b8f1429 100644 --- a/pagetop/src/core/component/context.rs +++ b/pagetop/src/core/component/context.rs @@ -2,13 +2,14 @@ use crate::config::SETTINGS; use crate::core::theme::all::theme_by_single_name; use crate::core::theme::ThemeTrait; use crate::html::*; -use crate::{base, concat_string, util, Lazy}; +use crate::{base, concat_string, util, LazyStatic}; -static DEFAULT_THEME: Lazy<&dyn ThemeTrait> = - Lazy::new(|| match theme_by_single_name(&SETTINGS.app.theme) { +static DEFAULT_THEME: LazyStatic<&dyn ThemeTrait> = LazyStatic::new(|| + match theme_by_single_name(&SETTINGS.app.theme) { Some(theme) => theme, None => &base::theme::bootsier::Bootsier, - }); + } +); pub enum InContextOp { SetTheme(&'static str), diff --git a/pagetop/src/core/hook/all.rs b/pagetop/src/core/hook/all.rs index 05b2f510..ab562311 100644 --- a/pagetop/src/core/hook/all.rs +++ b/pagetop/src/core/hook/all.rs @@ -1,12 +1,13 @@ use super::{HookAction, ActionsHolder}; -use crate::Lazy; +use crate::LazyStatic; use std::collections::HashMap; use std::sync::RwLock; // Registered actions. -static ACTIONS: Lazy>> = - Lazy::new(|| RwLock::new(HashMap::new())); +static ACTIONS: LazyStatic>> = LazyStatic::new(|| + RwLock::new(HashMap::new()) +); pub fn add_action(action: HookAction) { let mut actions = ACTIONS.write().unwrap(); diff --git a/pagetop/src/core/module/all.rs b/pagetop/src/core/module/all.rs index 87d952b1..4e6c6282 100644 --- a/pagetop/src/core/module/all.rs +++ b/pagetop/src/core/module/all.rs @@ -1,6 +1,6 @@ use super::ModuleTrait; use crate::core::hook::add_action; -use crate::{app, trace, Lazy}; +use crate::{app, trace, LazyStatic}; #[cfg(any(feature = "mysql", feature = "postgres", feature = "sqlite"))] use crate::{db::*, run_now}; @@ -8,7 +8,9 @@ use crate::{db::*, run_now}; use std::sync::RwLock; // Enabled modules. -static ENABLED_MODULES: Lazy>> = Lazy::new(|| RwLock::new(Vec::new())); +static ENABLED_MODULES: LazyStatic>> = LazyStatic::new(|| + RwLock::new(Vec::new()) +); /* Disabled modules. static DISABLED_MODULES: Lazy>> = Lazy::new(|| { diff --git a/pagetop/src/core/theme/all.rs b/pagetop/src/core/theme/all.rs index 46c6f699..923175fe 100644 --- a/pagetop/src/core/theme/all.rs +++ b/pagetop/src/core/theme/all.rs @@ -1,12 +1,14 @@ use super::ThemeTrait; -use crate::{app, theme_static_files, trace, Lazy}; +use crate::{app, theme_static_files, trace, LazyStatic}; use std::sync::RwLock; include!(concat!(env!("OUT_DIR"), "/theme.rs")); // Temas registrados. -static THEMES: Lazy>> = Lazy::new(|| RwLock::new(Vec::new())); +static THEMES: LazyStatic>> = LazyStatic::new(|| + RwLock::new(Vec::new()) +); pub fn register_themes(themes: Vec<&'static dyn ThemeTrait>) { for t in themes { diff --git a/pagetop/src/lib.rs b/pagetop/src/lib.rs index 5a33697c..5d788104 100644 --- a/pagetop/src/lib.rs +++ b/pagetop/src/lib.rs @@ -2,7 +2,7 @@ pub use concat_string::concat_string; pub use doc_comment::doc_comment; -pub use once_cell::sync::Lazy; +pub use once_cell::sync::Lazy as LazyStatic; // LOCAL. diff --git a/pagetop/src/prelude.rs b/pagetop/src/prelude.rs index 9ce6e3c7..3ad1f27c 100644 --- a/pagetop/src/prelude.rs +++ b/pagetop/src/prelude.rs @@ -1,7 +1,7 @@ //! Re-exporta recursos comunes. // Global macros and helpers. -pub use crate::{args, concat_string, theme_static_files, util}; +pub use crate::{args, concat_string, theme_static_files, util, LazyStatic}; pub use crate::config::SETTINGS; diff --git a/pagetop/src/response/page/definition.rs b/pagetop/src/response/page/definition.rs index e8437c81..bbd00059 100644 --- a/pagetop/src/response/page/definition.rs +++ b/pagetop/src/response/page/definition.rs @@ -4,11 +4,11 @@ use crate::config::SETTINGS; use crate::core::component::*; use crate::core::hook::{action_ref, run_actions}; use crate::html::*; -use crate::{trace, Lazy}; +use crate::{trace, LazyStatic}; use std::collections::HashMap; -static DEFAULT_LANGUAGE: Lazy> = Lazy::new(|| { +static DEFAULT_LANGUAGE: LazyStatic> = LazyStatic::new(|| { let language = SETTINGS.app.language[..2].to_lowercase(); if !language.is_empty() { Some(language) @@ -17,7 +17,7 @@ static DEFAULT_LANGUAGE: Lazy> = Lazy::new(|| { } }); -static DEFAULT_DIRECTION: Lazy> = Lazy::new(|| { +static DEFAULT_DIRECTION: LazyStatic> = LazyStatic::new(|| { let direction = SETTINGS.app.direction.to_lowercase(); match direction.as_str() { "auto" => Some("auto".to_owned()),