From ddf78c2de899ce7a8577aeff2c6d96c5f2e097e4 Mon Sep 17 00:00:00 2001 From: Manuel Cillero Date: Thu, 11 Sep 2025 19:03:34 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Unifica=20conversiones=20a=20Str?= =?UTF-8?q?ing=20con=20`to=5Fstring()`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Como `String::from()` y `.to_string()` son equivalentes, se sustituyen todas las ocurrencias de `String::from()` por `to_string()` para mayor coherencia y legibilidad. --- src/app.rs | 2 +- src/base/component/html.rs | 2 +- src/core/theme/regions.rs | 2 +- src/html.rs | 4 ++-- src/html/assets/favicon.rs | 2 +- src/html/attr_classes.rs | 2 +- src/html/attr_l10n.rs | 4 ++-- src/html/attr_value.rs | 2 +- src/html/context.rs | 10 +++++----- src/locale.rs | 4 ++-- src/util.rs | 22 +++++++++++----------- tests/component_html.rs | 2 +- 12 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/app.rs b/src/app.rs index 94d901f..c8ffba1 100644 --- a/src/app.rs +++ b/src/app.rs @@ -84,7 +84,7 @@ impl Application { if let Some((Width(term_width), _)) = terminal_size() { if term_width >= 80 { let maxlen: usize = ((term_width / 10) - 2).into(); - let mut app = app_name.substring(0, maxlen).to_owned(); + let mut app = app_name.substring(0, maxlen).to_string(); if app_name.len() > maxlen { app = format!("{app}..."); } diff --git a/src/base/component/html.rs b/src/base/component/html.rs index 7bde94a..8fa5690 100644 --- a/src/base/component/html.rs +++ b/src/base/component/html.rs @@ -25,7 +25,7 @@ use crate::prelude::*; /// use pagetop::prelude::*; /// /// let component = Html::with(|cx| { -/// let user = cx.param::("username").cloned().unwrap_or(String::from("visitor")); +/// let user = cx.param::("username").cloned().unwrap_or("visitor".to_string()); /// html! { /// h1 { "Hello, " (user) } /// } diff --git a/src/core/theme/regions.rs b/src/core/theme/regions.rs index 1a2e0fb..8082aac 100644 --- a/src/core/theme/regions.rs +++ b/src/core/theme/regions.rs @@ -36,7 +36,7 @@ impl Default for Region { fn default() -> Self { Self { key: REGION_CONTENT, - name: String::from(REGION_CONTENT), + name: REGION_CONTENT.to_string(), } } } diff --git a/src/html.rs b/src/html.rs index 9f3d70c..37ab3f4 100644 --- a/src/html.rs +++ b/src/html.rs @@ -71,11 +71,11 @@ pub type OptionComponent = core::component::Typed /// use pagetop::prelude::*; /// /// // Texto normal, se escapa automáticamente para evitar inyección de HTML. -/// let fragment = PrepareMarkup::Escaped(String::from("Hola mundo")); +/// let fragment = PrepareMarkup::Escaped("Hola mundo".to_string()); /// assert_eq!(fragment.render().into_string(), "Hola <b>mundo</b>"); /// /// // HTML literal, se inserta directamente, sin escapado adicional. -/// let raw_html = PrepareMarkup::Raw(String::from("negrita")); +/// let raw_html = PrepareMarkup::Raw("negrita".to_string()); /// assert_eq!(raw_html.render().into_string(), "negrita"); /// /// // Fragmento ya preparado con la macro `html!`. diff --git a/src/html/assets/favicon.rs b/src/html/assets/favicon.rs index 1a8b29e..e951df5 100644 --- a/src/html/assets/favicon.rs +++ b/src/html/assets/favicon.rs @@ -129,7 +129,7 @@ impl Favicon { icon_color: Option, ) -> Self { let icon_type = match icon_source.rfind('.') { - Some(i) => match icon_source[i..].to_owned().to_lowercase().as_str() { + Some(i) => match icon_source[i..].to_string().to_lowercase().as_str() { ".avif" => Some("image/avif"), ".gif" => Some("image/gif"), ".ico" => Some("image/x-icon"), diff --git a/src/html/attr_classes.rs b/src/html/attr_classes.rs index 91ccfaf..098c26c 100644 --- a/src/html/attr_classes.rs +++ b/src/html/attr_classes.rs @@ -37,7 +37,7 @@ pub enum ClassesOp { /// .with_value(ClassesOp::Add, "Active") /// .with_value(ClassesOp::Remove, "btn-primary"); /// -/// assert_eq!(classes.get(), Some(String::from("btn active"))); +/// assert_eq!(classes.get(), Some("btn active".to_string())); /// assert!(classes.contains("active")); /// ``` #[derive(AutoDefault, Clone, Debug)] diff --git a/src/html/attr_l10n.rs b/src/html/attr_l10n.rs index 3e8a4e4..8250c74 100644 --- a/src/html/attr_l10n.rs +++ b/src/html/attr_l10n.rs @@ -17,13 +17,13 @@ use crate::{builder_fn, AutoDefault}; /// // Español disponible. /// assert_eq!( /// hello.lookup(&LangMatch::resolve("es-ES")), -/// Some(String::from("¡Hola mundo!")) +/// Some("¡Hola mundo!".to_string()) /// ); /// /// // Japonés no disponible, traduce al idioma de respaldo ("en-US"). /// assert_eq!( /// hello.lookup(&LangMatch::resolve("ja-JP")), -/// Some(String::from("Hello world!")) +/// Some("Hello world!".to_string()) /// ); /// /// // Uso típico en un atributo: diff --git a/src/html/attr_value.rs b/src/html/attr_value.rs index c70229f..4e03120 100644 --- a/src/html/attr_value.rs +++ b/src/html/attr_value.rs @@ -36,7 +36,7 @@ impl AttrValue { self.0 = if value.is_empty() { None } else { - Some(value.to_owned()) + Some(value.to_string()) }; self } diff --git a/src/html/context.rs b/src/html/context.rs index 26e2478..8ef3a05 100644 --- a/src/html/context.rs +++ b/src/html/context.rs @@ -285,7 +285,7 @@ impl Context { /// /// let cx = Context::new(None) /// .with_param("usuario_id", 42_i32) - /// .with_param("titulo", String::from("Hola")); + /// .with_param("titulo", "Hola".to_string()); /// /// let id: &i32 = cx.get_param("usuario_id").unwrap(); /// let titulo: &String = cx.get_param("titulo").unwrap(); @@ -318,7 +318,7 @@ impl Context { /// /// let mut cx = Context::new(None) /// .with_param("contador", 7_i32) - /// .with_param("titulo", String::from("Hola")); + /// .with_param("titulo", "Hola".to_string()); /// /// let n: i32 = cx.take_param("contador").unwrap(); /// assert!(cx.get_param::("contador").is_err()); // ya no está @@ -416,7 +416,7 @@ impl Contextual for Context { /// /// let cx = Context::new(None) /// .with_param("usuario_id", 42_i32) - /// .with_param("titulo", String::from("Hola")) + /// .with_param("titulo", "Hola".to_string()) /// .with_param("flags", vec!["a", "b"]); /// ``` #[builder_fn] @@ -484,7 +484,7 @@ impl Contextual for Context { /// ```rust /// use pagetop::prelude::*; /// - /// let cx = Context::new(None).with_param("username", String::from("Alice")); + /// let cx = Context::new(None).with_param("username", "Alice".to_string()); /// /// // Devuelve Some(&String) si existe y coincide el tipo. /// assert_eq!(cx.param::("username").map(|s| s.as_str()), Some("Alice")); @@ -533,7 +533,7 @@ impl Contextual for Context { .replace(' ', "_") .to_lowercase(); let prefix = if prefix.is_empty() { - "prefix".to_owned() + "prefix".to_string() } else { prefix }; diff --git a/src/locale.rs b/src/locale.rs index cf44dd8..2bf0da9 100644 --- a/src/locale.rs +++ b/src/locale.rs @@ -165,7 +165,7 @@ pub trait LangId { /// /// // Idioma no soportado. /// let lang = LangMatch::resolve("ja-JP"); -/// assert_eq!(lang, LangMatch::Unsupported(String::from("ja-JP"))); +/// assert_eq!(lang, LangMatch::Unsupported("ja-JP".to_string())); /// ``` /// /// Con la siguiente instrucción siempre se obtiene un [`LanguageIdentifier`] válido, ya sea porque @@ -222,7 +222,7 @@ impl LangMatch { } // En caso contrario, indica que el idioma no está soportado. - Self::Unsupported(String::from(language)) + Self::Unsupported(language.to_string()) } /// Devuelve el [`LanguageIdentifier`] si el idioma fue reconocido. diff --git a/src/util.rs b/src/util.rs index 808014b..56b098d 100644 --- a/src/util.rs +++ b/src/util.rs @@ -110,15 +110,15 @@ macro_rules! hm { /// /// // Concatena todos los fragmentos directamente. /// let result = join!("Hello", " ", "World"); -/// assert_eq!(result, String::from("Hello World")); +/// assert_eq!(result, "Hello World".to_string()); /// /// // También funciona con valores vacíos. /// let result_with_empty = join!("Hello", "", "World"); -/// assert_eq!(result_with_empty, String::from("HelloWorld")); +/// assert_eq!(result_with_empty, "HelloWorld".to_string()); /// /// // Un único fragmento devuelve el mismo valor. /// let single_result = join!("Hello"); -/// assert_eq!(single_result, String::from("Hello")); +/// assert_eq!(single_result, "Hello".to_string()); /// ``` #[macro_export] macro_rules! join { @@ -141,11 +141,11 @@ macro_rules! join { /// /// // Concatena los fragmentos no vacíos con un espacio como separador. /// let result_with_separator = join_opt!(["Hello", "", "World"]; " "); -/// assert_eq!(result_with_separator, Some(String::from("Hello World"))); +/// assert_eq!(result_with_separator, Some("Hello World".to_string())); /// /// // Concatena los fragmentos no vacíos sin un separador. /// let result_without_separator = join_opt!(["Hello", "", "World"]); -/// assert_eq!(result_without_separator, Some(String::from("HelloWorld"))); +/// assert_eq!(result_without_separator, Some("HelloWorld".to_string())); /// /// // Devuelve `None` si todos los fragmentos están vacíos. /// let result_empty = join_opt!(["", "", ""]); @@ -185,19 +185,19 @@ macro_rules! join_opt { /// /// // Concatena los dos fragmentos cuando ambos no están vacíos. /// let result = join_pair!(first, separator, second); -/// assert_eq!(result, String::from("Hello-World")); +/// assert_eq!(result, "Hello-World".to_string()); /// /// // Si el primer fragmento está vacío, devuelve el segundo. /// let result_empty_first = join_pair!("", separator, second); -/// assert_eq!(result_empty_first, String::from("World")); +/// assert_eq!(result_empty_first, "World".to_string()); /// /// // Si el segundo fragmento está vacío, devuelve el primero. /// let result_empty_second = join_pair!(first, separator, ""); -/// assert_eq!(result_empty_second, String::from("Hello")); +/// assert_eq!(result_empty_second, "Hello".to_string()); /// /// // Si ambos fragmentos están vacíos, devuelve una cadena vacía. /// let result_both_empty = join_pair!("", separator, ""); -/// assert_eq!(result_both_empty, String::from("")); +/// assert_eq!(result_both_empty, "".to_string()); /// ``` #[macro_export] macro_rules! join_pair { @@ -224,11 +224,11 @@ macro_rules! join_pair { /// /// // Concatena los fragmentos. /// let result = join_strict!(["Hello", "World"]); -/// assert_eq!(result, Some(String::from("HelloWorld"))); +/// assert_eq!(result, Some("HelloWorld".to_string())); /// /// // Concatena los fragmentos con un separador. /// let result_with_separator = join_strict!(["Hello", "World"]; " "); -/// assert_eq!(result_with_separator, Some(String::from("Hello World"))); +/// assert_eq!(result_with_separator, Some("Hello World".to_string())); /// /// // Devuelve `None` si alguno de los fragmentos está vacío. /// let result_with_empty = join_strict!(["Hello", "", "World"]); diff --git a/tests/component_html.rs b/tests/component_html.rs index bd7f3c0..851315a 100644 --- a/tests/component_html.rs +++ b/tests/component_html.rs @@ -17,7 +17,7 @@ async fn component_html_renders_static_markup() { #[pagetop::test] async fn component_html_renders_using_context_param() { - let mut cx = Context::new(None).with_param("username", String::from("Alice")); + let mut cx = Context::new(None).with_param("username", "Alice".to_string()); let component = Html::with(|cx| { let name = cx.param::("username").cloned().unwrap_or_default();