From a153a69e513104901491044ba38f5da42d533c63 Mon Sep 17 00:00:00 2001 From: sshekhar563 Date: Sat, 11 Oct 2025 14:09:56 +0530 Subject: [PATCH 1/4] Add From<&Classes> impl to allow &Classes in element props (#3589) --- packages/yew/src/html/classes.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/yew/src/html/classes.rs b/packages/yew/src/html/classes.rs index 78ca7d83e7f..b6363cf90f5 100644 --- a/packages/yew/src/html/classes.rs +++ b/packages/yew/src/html/classes.rs @@ -276,6 +276,11 @@ impl, const SIZE: usize> From<[T; SIZE]> for Classes { t.into_iter().collect() } } +impl From<&Classes> for Classes { + fn from(c: &Classes) -> Self { + c.clone() + } +} impl PartialEq for Classes { fn eq(&self, other: &Self) -> bool { From 5cfa10187f6a76da73104712e84feaeb4bef7a36 Mon Sep 17 00:00:00 2001 From: Siddhant Shekhar Date: Sat, 11 Oct 2025 21:55:52 +0530 Subject: [PATCH 2/4] Update classes.rs --- packages/yew/src/html/classes.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/yew/src/html/classes.rs b/packages/yew/src/html/classes.rs index b6363cf90f5..4e4c1f7b946 100644 --- a/packages/yew/src/html/classes.rs +++ b/packages/yew/src/html/classes.rs @@ -282,6 +282,12 @@ impl From<&Classes> for Classes { } } +impl From<&Classes> for AttrValue { + fn from(c: &Classes) -> Self { + c.clone().into_prop_value() + } +} + impl PartialEq for Classes { fn eq(&self, other: &Self) -> bool { self.set.len() == other.set.len() && self.set.iter().eq(other.set.iter()) From 884b36b65fc6908e969d3312c725c0adf39dfbf8 Mon Sep 17 00:00:00 2001 From: Martin Molzer Date: Wed, 22 Oct 2025 15:40:17 +0200 Subject: [PATCH 3/4] bless error output adds an additional candidate to the impl block, which is fine --- packages/yew-macro/tests/html_macro/element-fail.stderr | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/yew-macro/tests/html_macro/element-fail.stderr b/packages/yew-macro/tests/html_macro/element-fail.stderr index 8488c5ceaa4..0778bb33660 100644 --- a/packages/yew-macro/tests/html_macro/element-fail.stderr +++ b/packages/yew-macro/tests/html_macro/element-fail.stderr @@ -695,6 +695,7 @@ error[E0277]: the trait bound `implicit_clone::unsync::string::IString: From<{in | ^^ the trait `From<{integer}>` is not implemented for `implicit_clone::unsync::string::IString` | = help: the following other types implement trait `From`: + `implicit_clone::unsync::string::IString` implements `From<&Classes>` `implicit_clone::unsync::string::IString` implements `From<&implicit_clone::unsync::string::IString>` `implicit_clone::unsync::string::IString` implements `From<&str>` `implicit_clone::unsync::string::IString` implements `From>` From 02efc440becfa235736c9fa30ec7c1edaae108bb Mon Sep 17 00:00:00 2001 From: Martin Molzer Date: Wed, 22 Oct 2025 15:46:10 +0200 Subject: [PATCH 4/4] bless more impl error messages --- .../tests/classes_macro/classes-fail.stderr | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/yew-macro/tests/classes_macro/classes-fail.stderr b/packages/yew-macro/tests/classes_macro/classes-fail.stderr index 2622e838ef0..4361dd082bc 100644 --- a/packages/yew-macro/tests/classes_macro/classes-fail.stderr +++ b/packages/yew-macro/tests/classes_macro/classes-fail.stderr @@ -17,6 +17,7 @@ error[E0277]: the trait bound `Classes: From<{integer}>` is not satisfied | ^^ the trait `From<{integer}>` is not implemented for `Classes` | = help: the following other types implement trait `From`: + `Classes` implements `From<&Classes>` `Classes` implements `From<&Option>` `Classes` implements `From<&String>` `Classes` implements `From<&[T]>` @@ -24,7 +25,6 @@ error[E0277]: the trait bound `Classes: From<{integer}>` is not satisfied `Classes` implements `From<&str>` `Classes` implements `From>` `Classes` implements `From>` - `Classes` implements `From` and $N others = note: required for `{integer}` to implement `Into` note: required by a bound in `Classes::push` @@ -40,6 +40,7 @@ error[E0277]: the trait bound `Classes: From<{float}>` is not satisfied | ^^^^ the trait `From<{float}>` is not implemented for `Classes` | = help: the following other types implement trait `From`: + `Classes` implements `From<&Classes>` `Classes` implements `From<&Option>` `Classes` implements `From<&String>` `Classes` implements `From<&[T]>` @@ -47,7 +48,6 @@ error[E0277]: the trait bound `Classes: From<{float}>` is not satisfied `Classes` implements `From<&str>` `Classes` implements `From>` `Classes` implements `From>` - `Classes` implements `From` and $N others = note: required for `{float}` to implement `Into` note: required by a bound in `Classes::push` @@ -66,6 +66,7 @@ error[E0277]: the trait bound `Classes: From<{integer}>` is not satisfied | required by a bound introduced by this call | = help: the following other types implement trait `From`: + `Classes` implements `From<&Classes>` `Classes` implements `From<&Option>` `Classes` implements `From<&String>` `Classes` implements `From<&[T]>` @@ -73,7 +74,6 @@ error[E0277]: the trait bound `Classes: From<{integer}>` is not satisfied `Classes` implements `From<&str>` `Classes` implements `From>` `Classes` implements `From>` - `Classes` implements `From` and $N others = note: required for `{integer}` to implement `Into` = note: required for `Classes` to implement `From>` @@ -92,6 +92,7 @@ error[E0277]: the trait bound `Classes: From<{integer}>` is not satisfied | ^^^^ the trait `From<{integer}>` is not implemented for `Classes` | = help: the following other types implement trait `From`: + `Classes` implements `From<&Classes>` `Classes` implements `From<&Option>` `Classes` implements `From<&String>` `Classes` implements `From<&[T]>` @@ -99,7 +100,6 @@ error[E0277]: the trait bound `Classes: From<{integer}>` is not satisfied `Classes` implements `From<&str>` `Classes` implements `From>` `Classes` implements `From>` - `Classes` implements `From` and $N others = note: required for `{integer}` to implement `Into` = note: required for `Classes` to implement `From>` @@ -118,6 +118,7 @@ error[E0277]: the trait bound `Classes: From` is not satisfied | ^^^^ the trait `From` is not implemented for `Classes` | = help: the following other types implement trait `From`: + `Classes` implements `From<&Classes>` `Classes` implements `From<&Option>` `Classes` implements `From<&String>` `Classes` implements `From<&[T]>` @@ -125,7 +126,6 @@ error[E0277]: the trait bound `Classes: From` is not satisfied `Classes` implements `From<&str>` `Classes` implements `From>` `Classes` implements `From>` - `Classes` implements `From` and $N others = note: required for `u32` to implement `Into` = note: required for `Classes` to implement `From>` @@ -144,6 +144,7 @@ error[E0277]: the trait bound `Classes: From<{integer}>` is not satisfied | ^^ the trait `From<{integer}>` is not implemented for `Classes` | = help: the following other types implement trait `From`: + `Classes` implements `From<&Classes>` `Classes` implements `From<&Option>` `Classes` implements `From<&String>` `Classes` implements `From<&[T]>` @@ -151,7 +152,6 @@ error[E0277]: the trait bound `Classes: From<{integer}>` is not satisfied `Classes` implements `From<&str>` `Classes` implements `From>` `Classes` implements `From>` - `Classes` implements `From` and $N others = note: required for `{integer}` to implement `Into` note: required by a bound in `Classes::push`