🚧 La macro args! tiene una nueva vida como kv!

This commit is contained in:
Manuel Cillero 2023-07-06 17:39:59 +02:00
parent 9552ae0af5
commit 8d05ec4b53
3 changed files with 10 additions and 14 deletions

View file

@ -90,7 +90,7 @@
//! Usa el componente [L10n](crate::base::components::L10n) para incluir textos y contenidos
//! opcionalmente traducibles según el contexto de renderizado.
use crate::{args, config, trace, LazyStatic};
use crate::{config, kv, trace, LazyStatic};
pub use fluent_templates;
@ -101,12 +101,12 @@ pub(crate) use unic_langid::{langid, LanguageIdentifier};
use std::collections::HashMap;
static LANGUAGES: LazyStatic<HashMap<String, (LanguageIdentifier, &str)>> = LazyStatic::new(|| {
args![
kv![
"en" => (langid!("en-US"), "English"),
"en-GB" => (langid!("en-GB"), "English (British)"),
"en-US" => (langid!("en-US"), "English (United States)"),
"es" => (langid!("es-ES"), "Spanish"),
"es-ES" => (langid!("es-ES"), "Spanish (Spain)")
"es-ES" => (langid!("es-ES"), "Spanish (Spain)"),
]
});

View file

@ -1,18 +1,14 @@
//! Re-exporta los tipos y funciones más habituales para la creación de soluciones web con
//! **PageTop**.
//! The PageTop Prelude.
// Re-exports.
pub use crate::{
concat_string, fn_builder, paste, Handle, HashMapResources, LazyStatic, ResultExt,
};
// Traducciones globales.
pub use crate::LOCALE_PAGETOP;
// Funciones y macros útiles.
pub use crate::util;
pub use crate::{action, action_after_prepare_component, action_before_prepare_component};
pub use crate::{args, serve_static_files, use_config, use_handle, use_locale, use_static};
pub use crate::{default_settings, kv, serve_static_files, use_handle, use_locale, use_static};
// *************************************************************************************************

View file

@ -64,17 +64,17 @@ pub fn single_type_name<T: ?Sized>() -> &'static str {
/// Macro para construir grupos de pares clave-valor.
///
/// ```rust#ignore
/// let args = args![
/// let args = kv![
/// "userName" => "Roberto",
/// "photoCount" => 3,
/// "userGender" => "male"
/// "userGender" => "male",
/// ];
/// ```
macro_rules! args {
( $($key:expr => $value:expr),* ) => {{
macro_rules! kv {
( $($key:expr => $value:expr),* $(,)? ) => {{
let mut a = std::collections::HashMap::new();
$(
a.insert(String::from($key), $value.into());
a.insert($key.into(), $value.into());
)*
a
}};