🎨 Unifica conversiones a String con to_string()

Como `String::from()` y `.to_string()` son equivalentes, se sustituyen
todas las ocurrencias de `String::from()` por `to_string()` para mayor
coherencia y legibilidad.
This commit is contained in:
Manuel Cillero 2025-09-11 19:03:34 +02:00
parent 2a4d6a7890
commit ddf78c2de8
12 changed files with 29 additions and 29 deletions

View file

@ -84,7 +84,7 @@ impl Application {
if let Some((Width(term_width), _)) = terminal_size() { if let Some((Width(term_width), _)) = terminal_size() {
if term_width >= 80 { if term_width >= 80 {
let maxlen: usize = ((term_width / 10) - 2).into(); 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 { if app_name.len() > maxlen {
app = format!("{app}..."); app = format!("{app}...");
} }

View file

@ -25,7 +25,7 @@ use crate::prelude::*;
/// use pagetop::prelude::*; /// use pagetop::prelude::*;
/// ///
/// let component = Html::with(|cx| { /// let component = Html::with(|cx| {
/// let user = cx.param::<String>("username").cloned().unwrap_or(String::from("visitor")); /// let user = cx.param::<String>("username").cloned().unwrap_or("visitor".to_string());
/// html! { /// html! {
/// h1 { "Hello, " (user) } /// h1 { "Hello, " (user) }
/// } /// }

View file

@ -36,7 +36,7 @@ impl Default for Region {
fn default() -> Self { fn default() -> Self {
Self { Self {
key: REGION_CONTENT, key: REGION_CONTENT,
name: String::from(REGION_CONTENT), name: REGION_CONTENT.to_string(),
} }
} }
} }

View file

@ -71,11 +71,11 @@ pub type OptionComponent<C: core::component::Component> = core::component::Typed
/// use pagetop::prelude::*; /// use pagetop::prelude::*;
/// ///
/// // Texto normal, se escapa automáticamente para evitar inyección de HTML. /// // Texto normal, se escapa automáticamente para evitar inyección de HTML.
/// let fragment = PrepareMarkup::Escaped(String::from("Hola <b>mundo</b>")); /// let fragment = PrepareMarkup::Escaped("Hola <b>mundo</b>".to_string());
/// assert_eq!(fragment.render().into_string(), "Hola &lt;b&gt;mundo&lt;/b&gt;"); /// assert_eq!(fragment.render().into_string(), "Hola &lt;b&gt;mundo&lt;/b&gt;");
/// ///
/// // HTML literal, se inserta directamente, sin escapado adicional. /// // HTML literal, se inserta directamente, sin escapado adicional.
/// let raw_html = PrepareMarkup::Raw(String::from("<b>negrita</b>")); /// let raw_html = PrepareMarkup::Raw("<b>negrita</b>".to_string());
/// assert_eq!(raw_html.render().into_string(), "<b>negrita</b>"); /// assert_eq!(raw_html.render().into_string(), "<b>negrita</b>");
/// ///
/// // Fragmento ya preparado con la macro `html!`. /// // Fragmento ya preparado con la macro `html!`.

View file

@ -129,7 +129,7 @@ impl Favicon {
icon_color: Option<String>, icon_color: Option<String>,
) -> Self { ) -> Self {
let icon_type = match icon_source.rfind('.') { 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"), ".avif" => Some("image/avif"),
".gif" => Some("image/gif"), ".gif" => Some("image/gif"),
".ico" => Some("image/x-icon"), ".ico" => Some("image/x-icon"),

View file

@ -37,7 +37,7 @@ pub enum ClassesOp {
/// .with_value(ClassesOp::Add, "Active") /// .with_value(ClassesOp::Add, "Active")
/// .with_value(ClassesOp::Remove, "btn-primary"); /// .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")); /// assert!(classes.contains("active"));
/// ``` /// ```
#[derive(AutoDefault, Clone, Debug)] #[derive(AutoDefault, Clone, Debug)]

View file

@ -17,13 +17,13 @@ use crate::{builder_fn, AutoDefault};
/// // Español disponible. /// // Español disponible.
/// assert_eq!( /// assert_eq!(
/// hello.lookup(&LangMatch::resolve("es-ES")), /// 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"). /// // Japonés no disponible, traduce al idioma de respaldo ("en-US").
/// assert_eq!( /// assert_eq!(
/// hello.lookup(&LangMatch::resolve("ja-JP")), /// hello.lookup(&LangMatch::resolve("ja-JP")),
/// Some(String::from("Hello world!")) /// Some("Hello world!".to_string())
/// ); /// );
/// ///
/// // Uso típico en un atributo: /// // Uso típico en un atributo:

View file

@ -36,7 +36,7 @@ impl AttrValue {
self.0 = if value.is_empty() { self.0 = if value.is_empty() {
None None
} else { } else {
Some(value.to_owned()) Some(value.to_string())
}; };
self self
} }

View file

@ -285,7 +285,7 @@ impl Context {
/// ///
/// let cx = Context::new(None) /// let cx = Context::new(None)
/// .with_param("usuario_id", 42_i32) /// .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 id: &i32 = cx.get_param("usuario_id").unwrap();
/// let titulo: &String = cx.get_param("titulo").unwrap(); /// let titulo: &String = cx.get_param("titulo").unwrap();
@ -318,7 +318,7 @@ impl Context {
/// ///
/// let mut cx = Context::new(None) /// let mut cx = Context::new(None)
/// .with_param("contador", 7_i32) /// .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(); /// let n: i32 = cx.take_param("contador").unwrap();
/// assert!(cx.get_param::<i32>("contador").is_err()); // ya no está /// assert!(cx.get_param::<i32>("contador").is_err()); // ya no está
@ -416,7 +416,7 @@ impl Contextual for Context {
/// ///
/// let cx = Context::new(None) /// let cx = Context::new(None)
/// .with_param("usuario_id", 42_i32) /// .with_param("usuario_id", 42_i32)
/// .with_param("titulo", String::from("Hola")) /// .with_param("titulo", "Hola".to_string())
/// .with_param("flags", vec!["a", "b"]); /// .with_param("flags", vec!["a", "b"]);
/// ``` /// ```
#[builder_fn] #[builder_fn]
@ -484,7 +484,7 @@ impl Contextual for Context {
/// ```rust /// ```rust
/// use pagetop::prelude::*; /// 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. /// // Devuelve Some(&String) si existe y coincide el tipo.
/// assert_eq!(cx.param::<String>("username").map(|s| s.as_str()), Some("Alice")); /// assert_eq!(cx.param::<String>("username").map(|s| s.as_str()), Some("Alice"));
@ -533,7 +533,7 @@ impl Contextual for Context {
.replace(' ', "_") .replace(' ', "_")
.to_lowercase(); .to_lowercase();
let prefix = if prefix.is_empty() { let prefix = if prefix.is_empty() {
"prefix".to_owned() "prefix".to_string()
} else { } else {
prefix prefix
}; };

View file

@ -165,7 +165,7 @@ pub trait LangId {
/// ///
/// // Idioma no soportado. /// // Idioma no soportado.
/// let lang = LangMatch::resolve("ja-JP"); /// 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 /// 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. // 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. /// Devuelve el [`LanguageIdentifier`] si el idioma fue reconocido.

View file

@ -110,15 +110,15 @@ macro_rules! hm {
/// ///
/// // Concatena todos los fragmentos directamente. /// // Concatena todos los fragmentos directamente.
/// let result = join!("Hello", " ", "World"); /// 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. /// // También funciona con valores vacíos.
/// let result_with_empty = join!("Hello", "", "World"); /// 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. /// // Un único fragmento devuelve el mismo valor.
/// let single_result = join!("Hello"); /// let single_result = join!("Hello");
/// assert_eq!(single_result, String::from("Hello")); /// assert_eq!(single_result, "Hello".to_string());
/// ``` /// ```
#[macro_export] #[macro_export]
macro_rules! join { macro_rules! join {
@ -141,11 +141,11 @@ macro_rules! join {
/// ///
/// // Concatena los fragmentos no vacíos con un espacio como separador. /// // Concatena los fragmentos no vacíos con un espacio como separador.
/// let result_with_separator = join_opt!(["Hello", "", "World"]; " "); /// 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. /// // Concatena los fragmentos no vacíos sin un separador.
/// let result_without_separator = join_opt!(["Hello", "", "World"]); /// 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. /// // Devuelve `None` si todos los fragmentos están vacíos.
/// let result_empty = join_opt!(["", "", ""]); /// let result_empty = join_opt!(["", "", ""]);
@ -185,19 +185,19 @@ macro_rules! join_opt {
/// ///
/// // Concatena los dos fragmentos cuando ambos no están vacíos. /// // Concatena los dos fragmentos cuando ambos no están vacíos.
/// let result = join_pair!(first, separator, second); /// 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. /// // Si el primer fragmento está vacío, devuelve el segundo.
/// let result_empty_first = join_pair!("", separator, second); /// 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. /// // Si el segundo fragmento está vacío, devuelve el primero.
/// let result_empty_second = join_pair!(first, separator, ""); /// 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. /// // Si ambos fragmentos están vacíos, devuelve una cadena vacía.
/// let result_both_empty = join_pair!("", separator, ""); /// let result_both_empty = join_pair!("", separator, "");
/// assert_eq!(result_both_empty, String::from("")); /// assert_eq!(result_both_empty, "".to_string());
/// ``` /// ```
#[macro_export] #[macro_export]
macro_rules! join_pair { macro_rules! join_pair {
@ -224,11 +224,11 @@ macro_rules! join_pair {
/// ///
/// // Concatena los fragmentos. /// // Concatena los fragmentos.
/// let result = join_strict!(["Hello", "World"]); /// 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. /// // Concatena los fragmentos con un separador.
/// let result_with_separator = join_strict!(["Hello", "World"]; " "); /// 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. /// // Devuelve `None` si alguno de los fragmentos está vacío.
/// let result_with_empty = join_strict!(["Hello", "", "World"]); /// let result_with_empty = join_strict!(["Hello", "", "World"]);

View file

@ -17,7 +17,7 @@ async fn component_html_renders_static_markup() {
#[pagetop::test] #[pagetop::test]
async fn component_html_renders_using_context_param() { 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 component = Html::with(|cx| {
let name = cx.param::<String>("username").cloned().unwrap_or_default(); let name = cx.param::<String>("username").cloned().unwrap_or_default();