Actualiza la denominación Lazy por LazyStatic
This commit is contained in:
parent
280fa4cac1
commit
a7105d6a63
14 changed files with 56 additions and 47 deletions
|
|
@ -3,7 +3,7 @@ use crate::config::SETTINGS;
|
||||||
use crate::core::{module, theme};
|
use crate::core::{module, theme};
|
||||||
use crate::html::Markup;
|
use crate::html::Markup;
|
||||||
use crate::response::page::ResultPage;
|
use crate::response::page::ResultPage;
|
||||||
use crate::{base, trace, Lazy};
|
use crate::{base, trace, LazyStatic};
|
||||||
|
|
||||||
use actix_web::dev::Server;
|
use actix_web::dev::Server;
|
||||||
use std::io::Error;
|
use std::io::Error;
|
||||||
|
|
@ -18,14 +18,14 @@ impl Application {
|
||||||
super::banner::print_on_startup();
|
super::banner::print_on_startup();
|
||||||
|
|
||||||
// Inicia registro de trazas y eventos.
|
// Inicia registro de trazas y eventos.
|
||||||
Lazy::force(&super::tracing::TRACING);
|
LazyStatic::force(&super::tracing::TRACING);
|
||||||
|
|
||||||
// Valida el identificador de idioma.
|
// Valida el identificador de idioma.
|
||||||
Lazy::force(&super::locale::LANGID);
|
LazyStatic::force(&super::locale::LANGID);
|
||||||
|
|
||||||
// Conecta con la base de datos (opcional).
|
// Conecta con la base de datos (opcional).
|
||||||
#[cfg(any(feature = "mysql", feature = "postgres", feature = "sqlite"))]
|
#[cfg(any(feature = "mysql", feature = "postgres", feature = "sqlite"))]
|
||||||
Lazy::force(&super::db::DBCONN);
|
LazyStatic::force(&super::db::DBCONN);
|
||||||
|
|
||||||
// Habilita los módulos predeterminados.
|
// Habilita los módulos predeterminados.
|
||||||
module::all::enable_modules(vec![&base::module::homepage::DefaultHomePage]);
|
module::all::enable_modules(vec![&base::module::homepage::DefaultHomePage]);
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
use crate::config::SETTINGS;
|
use crate::config::SETTINGS;
|
||||||
use crate::Lazy;
|
use crate::LazyStatic;
|
||||||
|
|
||||||
use figlet_rs::FIGfont;
|
use figlet_rs::FIGfont;
|
||||||
|
|
||||||
pub static FIGFONT: Lazy<FIGfont> = Lazy::new(|| {
|
pub static FIGFONT: LazyStatic<FIGfont> = LazyStatic::new(|| {
|
||||||
let slant = include_str!("slant.flf");
|
let slant = include_str!("slant.flf");
|
||||||
let small = include_str!("small.flf");
|
let small = include_str!("small.flf");
|
||||||
let speed = include_str!("speed.flf");
|
let speed = include_str!("speed.flf");
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
use crate::config::SETTINGS;
|
use crate::config::SETTINGS;
|
||||||
use crate::db::*;
|
use crate::db::*;
|
||||||
use crate::{run_now, trace, Lazy};
|
use crate::{run_now, trace, LazyStatic};
|
||||||
|
|
||||||
use sea_orm::{ConnectOptions, ConnectionTrait, Database, DatabaseBackend, Statement};
|
use sea_orm::{ConnectOptions, ConnectionTrait, Database, DatabaseBackend, Statement};
|
||||||
use tracing_unwrap::ResultExt;
|
use tracing_unwrap::ResultExt;
|
||||||
|
|
||||||
pub static DBCONN: Lazy<DbConn> = Lazy::new(|| {
|
pub static DBCONN: LazyStatic<DbConn> = LazyStatic::new(|| {
|
||||||
trace::info!(
|
trace::info!(
|
||||||
"Connecting to database \"{}\" using a pool of {} connections",
|
"Connecting to database \"{}\" using a pool of {} connections",
|
||||||
&SETTINGS.database.db_name,
|
&SETTINGS.database.db_name,
|
||||||
|
|
@ -61,7 +61,7 @@ pub static DBCONN: Lazy<DbConn> = Lazy::new(|| {
|
||||||
.expect_or_log("Failed to connect to database")
|
.expect_or_log("Failed to connect to database")
|
||||||
});
|
});
|
||||||
|
|
||||||
static DBBACKEND: Lazy<DatabaseBackend> = Lazy::new(|| DBCONN.get_database_backend());
|
static DBBACKEND: LazyStatic<DatabaseBackend> = LazyStatic::new(|| DBCONN.get_database_backend());
|
||||||
|
|
||||||
pub async fn query<Q: QueryStatementWriter>(stmt: &mut Q) -> Result<Vec<QueryResult>, DbErr> {
|
pub async fn query<Q: QueryStatementWriter>(stmt: &mut Q) -> Result<Vec<QueryResult>, DbErr> {
|
||||||
DBCONN
|
DBCONN
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,24 @@
|
||||||
use crate::config::SETTINGS;
|
use crate::config::SETTINGS;
|
||||||
use crate::{trace, Lazy};
|
use crate::{trace, LazyStatic};
|
||||||
|
|
||||||
use unic_langid::LanguageIdentifier;
|
use unic_langid::LanguageIdentifier;
|
||||||
|
|
||||||
/// Almacena el Identificador de Idioma Unicode ([Unicode Language Identifier]
|
/// Almacena el Identificador de Idioma Unicode ([Unicode Language Identifier]
|
||||||
/// (https://unicode.org/reports/tr35/tr35.html#Unicode_language_identifier)) de
|
/// (https://unicode.org/reports/tr35/tr35.html#Unicode_language_identifier)) de
|
||||||
/// la aplicación, obtenido de `SETTINGS.app.language`.
|
/// la aplicación, obtenido de `SETTINGS.app.language`.
|
||||||
pub static LANGID: Lazy<LanguageIdentifier> = Lazy::new(|| match SETTINGS.app.language.parse() {
|
pub static LANGID: LazyStatic<LanguageIdentifier> = LazyStatic::new(||
|
||||||
Ok(language) => language,
|
match SETTINGS.app.language.parse() {
|
||||||
Err(_) => {
|
Ok(language) => language,
|
||||||
trace::warn!(
|
Err(_) => {
|
||||||
"{}, {} \"{}\"! {}, {}",
|
trace::warn!(
|
||||||
"Failed to parse language",
|
"{}, {} \"{}\"! {}, {}",
|
||||||
"unrecognized Unicode Language Identifier",
|
"Failed to parse language",
|
||||||
SETTINGS.app.language,
|
"unrecognized Unicode Language Identifier",
|
||||||
"Using \"en-US\"",
|
SETTINGS.app.language,
|
||||||
"check the settings file",
|
"Using \"en-US\"",
|
||||||
);
|
"check the settings file",
|
||||||
"en-US".parse().unwrap()
|
);
|
||||||
|
"en-US".parse().unwrap()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::config::SETTINGS;
|
use crate::config::SETTINGS;
|
||||||
use crate::Lazy;
|
use crate::LazyStatic;
|
||||||
|
|
||||||
use tracing_appender::non_blocking::WorkerGuard;
|
use tracing_appender::non_blocking::WorkerGuard;
|
||||||
use tracing_subscriber::EnvFilter;
|
use tracing_subscriber::EnvFilter;
|
||||||
|
|
@ -17,7 +17,7 @@ use tracing_subscriber::EnvFilter;
|
||||||
/// `Lazy<WorkerGuard>` se garantiza que todos los registros almacenados se
|
/// `Lazy<WorkerGuard>` se garantiza que todos los registros almacenados se
|
||||||
/// enviarán antes de terminar la ejecución.
|
/// enviarán antes de terminar la ejecución.
|
||||||
|
|
||||||
pub static TRACING: Lazy<WorkerGuard> = Lazy::new(|| {
|
pub static TRACING: LazyStatic<WorkerGuard> = LazyStatic::new(|| {
|
||||||
let env_filter = EnvFilter::try_new(&SETTINGS.log.tracing).unwrap_or_else(|_| EnvFilter::new("Info"));
|
let env_filter = EnvFilter::try_new(&SETTINGS.log.tracing).unwrap_or_else(|_| EnvFilter::new("Info"));
|
||||||
|
|
||||||
let rolling = SETTINGS.log.rolling.to_lowercase();
|
let rolling = SETTINGS.log.rolling.to_lowercase();
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::Lazy;
|
use crate::LazyStatic;
|
||||||
|
|
||||||
use config_rs::{Config, File};
|
use config_rs::{Config, File};
|
||||||
use serde::Deserialize;
|
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
|
/// 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
|
/// 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.
|
/// aplicación, o también de un tema, módulo o componente.
|
||||||
pub static CONFIG: Lazy<Config> = Lazy::new(|| {
|
pub static CONFIG: LazyStatic<Config> = LazyStatic::new(|| {
|
||||||
// Establece el modo de ejecución según el valor de la variable de entorno
|
// Establece el modo de ejecución según el valor de la variable de entorno
|
||||||
// PAGETOP_RUN_MODE. Asume "default" por defecto.
|
// PAGETOP_RUN_MODE. Asume "default" por defecto.
|
||||||
let run_mode = env::var("PAGETOP_RUN_MODE").unwrap_or_else(|_| "default".into());
|
let run_mode = env::var("PAGETOP_RUN_MODE").unwrap_or_else(|_| "default".into());
|
||||||
|
|
@ -48,7 +48,7 @@ macro_rules! config_map {
|
||||||
$crate::doc_comment! {
|
$crate::doc_comment! {
|
||||||
concat!($doc),
|
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();
|
let mut settings = $crate::config::CONFIG.clone();
|
||||||
$(
|
$(
|
||||||
settings.set_default($key, $value).unwrap();
|
settings.set_default($key, $value).unwrap();
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
use super::{ComponentTrait, ComponentsBundle};
|
use super::{ComponentTrait, ComponentsBundle};
|
||||||
use crate::Lazy;
|
use crate::LazyStatic;
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::RwLock;
|
use std::sync::RwLock;
|
||||||
|
|
||||||
static COMPONENTS: Lazy<RwLock<HashMap<&str, ComponentsBundle>>> =
|
static COMPONENTS: LazyStatic<RwLock<HashMap<&str, ComponentsBundle>>> = LazyStatic::new(||
|
||||||
Lazy::new(|| RwLock::new(HashMap::new()));
|
RwLock::new(HashMap::new())
|
||||||
|
);
|
||||||
|
|
||||||
pub fn add_component_to(region: &'static str, component: impl ComponentTrait) {
|
pub fn add_component_to(region: &'static str, component: impl ComponentTrait) {
|
||||||
let mut hmap = COMPONENTS.write().unwrap();
|
let mut hmap = COMPONENTS.write().unwrap();
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,14 @@ use crate::config::SETTINGS;
|
||||||
use crate::core::theme::all::theme_by_single_name;
|
use crate::core::theme::all::theme_by_single_name;
|
||||||
use crate::core::theme::ThemeTrait;
|
use crate::core::theme::ThemeTrait;
|
||||||
use crate::html::*;
|
use crate::html::*;
|
||||||
use crate::{base, concat_string, util, Lazy};
|
use crate::{base, concat_string, util, LazyStatic};
|
||||||
|
|
||||||
static DEFAULT_THEME: Lazy<&dyn ThemeTrait> =
|
static DEFAULT_THEME: LazyStatic<&dyn ThemeTrait> = LazyStatic::new(||
|
||||||
Lazy::new(|| match theme_by_single_name(&SETTINGS.app.theme) {
|
match theme_by_single_name(&SETTINGS.app.theme) {
|
||||||
Some(theme) => theme,
|
Some(theme) => theme,
|
||||||
None => &base::theme::bootsier::Bootsier,
|
None => &base::theme::bootsier::Bootsier,
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
pub enum InContextOp {
|
pub enum InContextOp {
|
||||||
SetTheme(&'static str),
|
SetTheme(&'static str),
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,13 @@
|
||||||
use super::{HookAction, ActionsHolder};
|
use super::{HookAction, ActionsHolder};
|
||||||
use crate::Lazy;
|
use crate::LazyStatic;
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::RwLock;
|
use std::sync::RwLock;
|
||||||
|
|
||||||
// Registered actions.
|
// Registered actions.
|
||||||
static ACTIONS: Lazy<RwLock<HashMap<&str, ActionsHolder>>> =
|
static ACTIONS: LazyStatic<RwLock<HashMap<&str, ActionsHolder>>> = LazyStatic::new(||
|
||||||
Lazy::new(|| RwLock::new(HashMap::new()));
|
RwLock::new(HashMap::new())
|
||||||
|
);
|
||||||
|
|
||||||
pub fn add_action(action: HookAction) {
|
pub fn add_action(action: HookAction) {
|
||||||
let mut actions = ACTIONS.write().unwrap();
|
let mut actions = ACTIONS.write().unwrap();
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use super::ModuleTrait;
|
use super::ModuleTrait;
|
||||||
use crate::core::hook::add_action;
|
use crate::core::hook::add_action;
|
||||||
use crate::{app, trace, Lazy};
|
use crate::{app, trace, LazyStatic};
|
||||||
|
|
||||||
#[cfg(any(feature = "mysql", feature = "postgres", feature = "sqlite"))]
|
#[cfg(any(feature = "mysql", feature = "postgres", feature = "sqlite"))]
|
||||||
use crate::{db::*, run_now};
|
use crate::{db::*, run_now};
|
||||||
|
|
@ -8,7 +8,9 @@ use crate::{db::*, run_now};
|
||||||
use std::sync::RwLock;
|
use std::sync::RwLock;
|
||||||
|
|
||||||
// Enabled modules.
|
// Enabled modules.
|
||||||
static ENABLED_MODULES: Lazy<RwLock<Vec<&dyn ModuleTrait>>> = Lazy::new(|| RwLock::new(Vec::new()));
|
static ENABLED_MODULES: LazyStatic<RwLock<Vec<&dyn ModuleTrait>>> = LazyStatic::new(||
|
||||||
|
RwLock::new(Vec::new())
|
||||||
|
);
|
||||||
|
|
||||||
/* Disabled modules.
|
/* Disabled modules.
|
||||||
static DISABLED_MODULES: Lazy<RwLock<Vec<&dyn ModuleTrait>>> = Lazy::new(|| {
|
static DISABLED_MODULES: Lazy<RwLock<Vec<&dyn ModuleTrait>>> = Lazy::new(|| {
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,14 @@
|
||||||
use super::ThemeTrait;
|
use super::ThemeTrait;
|
||||||
use crate::{app, theme_static_files, trace, Lazy};
|
use crate::{app, theme_static_files, trace, LazyStatic};
|
||||||
|
|
||||||
use std::sync::RwLock;
|
use std::sync::RwLock;
|
||||||
|
|
||||||
include!(concat!(env!("OUT_DIR"), "/theme.rs"));
|
include!(concat!(env!("OUT_DIR"), "/theme.rs"));
|
||||||
|
|
||||||
// Temas registrados.
|
// Temas registrados.
|
||||||
static THEMES: Lazy<RwLock<Vec<&dyn ThemeTrait>>> = Lazy::new(|| RwLock::new(Vec::new()));
|
static THEMES: LazyStatic<RwLock<Vec<&dyn ThemeTrait>>> = LazyStatic::new(||
|
||||||
|
RwLock::new(Vec::new())
|
||||||
|
);
|
||||||
|
|
||||||
pub fn register_themes(themes: Vec<&'static dyn ThemeTrait>) {
|
pub fn register_themes(themes: Vec<&'static dyn ThemeTrait>) {
|
||||||
for t in themes {
|
for t in themes {
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
pub use concat_string::concat_string;
|
pub use concat_string::concat_string;
|
||||||
pub use doc_comment::doc_comment;
|
pub use doc_comment::doc_comment;
|
||||||
pub use once_cell::sync::Lazy;
|
pub use once_cell::sync::Lazy as LazyStatic;
|
||||||
|
|
||||||
// LOCAL.
|
// LOCAL.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
//! Re-exporta recursos comunes.
|
//! Re-exporta recursos comunes.
|
||||||
|
|
||||||
// Global macros and helpers.
|
// 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;
|
pub use crate::config::SETTINGS;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,11 @@ use crate::config::SETTINGS;
|
||||||
use crate::core::component::*;
|
use crate::core::component::*;
|
||||||
use crate::core::hook::{action_ref, run_actions};
|
use crate::core::hook::{action_ref, run_actions};
|
||||||
use crate::html::*;
|
use crate::html::*;
|
||||||
use crate::{trace, Lazy};
|
use crate::{trace, LazyStatic};
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
static DEFAULT_LANGUAGE: Lazy<Option<String>> = Lazy::new(|| {
|
static DEFAULT_LANGUAGE: LazyStatic<Option<String>> = LazyStatic::new(|| {
|
||||||
let language = SETTINGS.app.language[..2].to_lowercase();
|
let language = SETTINGS.app.language[..2].to_lowercase();
|
||||||
if !language.is_empty() {
|
if !language.is_empty() {
|
||||||
Some(language)
|
Some(language)
|
||||||
|
|
@ -17,7 +17,7 @@ static DEFAULT_LANGUAGE: Lazy<Option<String>> = Lazy::new(|| {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
static DEFAULT_DIRECTION: Lazy<Option<String>> = Lazy::new(|| {
|
static DEFAULT_DIRECTION: LazyStatic<Option<String>> = LazyStatic::new(|| {
|
||||||
let direction = SETTINGS.app.direction.to_lowercase();
|
let direction = SETTINGS.app.direction.to_lowercase();
|
||||||
match direction.as_str() {
|
match direction.as_str() {
|
||||||
"auto" => Some("auto".to_owned()),
|
"auto" => Some("auto".to_owned()),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue