From 433a0f2eca42c665bea30de9d68cab63b50fafcf Mon Sep 17 00:00:00 2001 From: flumm Date: Tue, 13 May 2025 14:06:17 +0200 Subject: [PATCH] Avoid string copy for Key: From implementation (#3858) The macro uses `to_string().as_str()` which copies the string. Avoid that by using `as_str()` directly on the source. Signed-off-by: Dominik Csapak --- packages/yew/src/virtual_dom/key.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/yew/src/virtual_dom/key.rs b/packages/yew/src/virtual_dom/key.rs index 0792f649d..88f147de0 100644 --- a/packages/yew/src/virtual_dom/key.rs +++ b/packages/yew/src/virtual_dom/key.rs @@ -41,6 +41,12 @@ impl From<&'_ str> for Key { } } +impl From for Key { + fn from(key: String) -> Self { + Self::from(key.as_str()) + } +} + impl ImplicitClone for Key {} macro_rules! key_impl_from_to_string { @@ -53,7 +59,6 @@ macro_rules! key_impl_from_to_string { }; } -key_impl_from_to_string!(String); key_impl_from_to_string!(char); key_impl_from_to_string!(u8); key_impl_from_to_string!(u16);