Skip to content

Commit 38e7f2b

Browse files
Inconsistent clone() requirement when passing Classes to HTML elements vs. components (#3589) (#3931)
* Add From<&Classes> impl to allow &Classes in element props (#3589) * bless macro test error output adds an additional candidate to the impl block, which is fine --------- Co-authored-by: Martin Molzer <WorldSEnder@users.noreply.github.com>
1 parent 0c98674 commit 38e7f2b

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

packages/yew-macro/tests/classes_macro/classes-fail.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ error[E0277]: the trait bound `Classes: From<{integer}>` is not satisfied
1717
| ^^ the trait `From<{integer}>` is not implemented for `Classes`
1818
|
1919
= help: the following other types implement trait `From<T>`:
20+
`Classes` implements `From<&Classes>`
2021
`Classes` implements `From<&Option<T>>`
2122
`Classes` implements `From<&String>`
2223
`Classes` implements `From<&[T]>`
2324
`Classes` implements `From<&implicit_clone::unsync::string::IString>`
2425
`Classes` implements `From<&str>`
2526
`Classes` implements `From<Cow<'_, str>>`
2627
`Classes` implements `From<Option<T>>`
27-
`Classes` implements `From<String>`
2828
and $N others
2929
= note: required for `{integer}` to implement `Into<Classes>`
3030
note: required by a bound in `Classes::push`
@@ -40,14 +40,14 @@ error[E0277]: the trait bound `Classes: From<{float}>` is not satisfied
4040
| ^^^^ the trait `From<{float}>` is not implemented for `Classes`
4141
|
4242
= help: the following other types implement trait `From<T>`:
43+
`Classes` implements `From<&Classes>`
4344
`Classes` implements `From<&Option<T>>`
4445
`Classes` implements `From<&String>`
4546
`Classes` implements `From<&[T]>`
4647
`Classes` implements `From<&implicit_clone::unsync::string::IString>`
4748
`Classes` implements `From<&str>`
4849
`Classes` implements `From<Cow<'_, str>>`
4950
`Classes` implements `From<Option<T>>`
50-
`Classes` implements `From<String>`
5151
and $N others
5252
= note: required for `{float}` to implement `Into<Classes>`
5353
note: required by a bound in `Classes::push`
@@ -66,14 +66,14 @@ error[E0277]: the trait bound `Classes: From<{integer}>` is not satisfied
6666
| required by a bound introduced by this call
6767
|
6868
= help: the following other types implement trait `From<T>`:
69+
`Classes` implements `From<&Classes>`
6970
`Classes` implements `From<&Option<T>>`
7071
`Classes` implements `From<&String>`
7172
`Classes` implements `From<&[T]>`
7273
`Classes` implements `From<&implicit_clone::unsync::string::IString>`
7374
`Classes` implements `From<&str>`
7475
`Classes` implements `From<Cow<'_, str>>`
7576
`Classes` implements `From<Option<T>>`
76-
`Classes` implements `From<String>`
7777
and $N others
7878
= note: required for `{integer}` to implement `Into<Classes>`
7979
= note: required for `Classes` to implement `From<Vec<{integer}>>`
@@ -92,14 +92,14 @@ error[E0277]: the trait bound `Classes: From<{integer}>` is not satisfied
9292
| ^^^^ the trait `From<{integer}>` is not implemented for `Classes`
9393
|
9494
= help: the following other types implement trait `From<T>`:
95+
`Classes` implements `From<&Classes>`
9596
`Classes` implements `From<&Option<T>>`
9697
`Classes` implements `From<&String>`
9798
`Classes` implements `From<&[T]>`
9899
`Classes` implements `From<&implicit_clone::unsync::string::IString>`
99100
`Classes` implements `From<&str>`
100101
`Classes` implements `From<Cow<'_, str>>`
101102
`Classes` implements `From<Option<T>>`
102-
`Classes` implements `From<String>`
103103
and $N others
104104
= note: required for `{integer}` to implement `Into<Classes>`
105105
= note: required for `Classes` to implement `From<Option<{integer}>>`
@@ -118,14 +118,14 @@ error[E0277]: the trait bound `Classes: From<u32>` is not satisfied
118118
| ^^^^ the trait `From<u32>` is not implemented for `Classes`
119119
|
120120
= help: the following other types implement trait `From<T>`:
121+
`Classes` implements `From<&Classes>`
121122
`Classes` implements `From<&Option<T>>`
122123
`Classes` implements `From<&String>`
123124
`Classes` implements `From<&[T]>`
124125
`Classes` implements `From<&implicit_clone::unsync::string::IString>`
125126
`Classes` implements `From<&str>`
126127
`Classes` implements `From<Cow<'_, str>>`
127128
`Classes` implements `From<Option<T>>`
128-
`Classes` implements `From<String>`
129129
and $N others
130130
= note: required for `u32` to implement `Into<Classes>`
131131
= note: required for `Classes` to implement `From<Option<u32>>`
@@ -144,14 +144,14 @@ error[E0277]: the trait bound `Classes: From<{integer}>` is not satisfied
144144
| ^^ the trait `From<{integer}>` is not implemented for `Classes`
145145
|
146146
= help: the following other types implement trait `From<T>`:
147+
`Classes` implements `From<&Classes>`
147148
`Classes` implements `From<&Option<T>>`
148149
`Classes` implements `From<&String>`
149150
`Classes` implements `From<&[T]>`
150151
`Classes` implements `From<&implicit_clone::unsync::string::IString>`
151152
`Classes` implements `From<&str>`
152153
`Classes` implements `From<Cow<'_, str>>`
153154
`Classes` implements `From<Option<T>>`
154-
`Classes` implements `From<String>`
155155
and $N others
156156
= note: required for `{integer}` to implement `Into<Classes>`
157157
note: required by a bound in `Classes::push`

packages/yew-macro/tests/html_macro/element-fail.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,7 @@ error[E0277]: the trait bound `implicit_clone::unsync::string::IString: From<{in
695695
| ^^ the trait `From<{integer}>` is not implemented for `implicit_clone::unsync::string::IString`
696696
|
697697
= help: the following other types implement trait `From<T>`:
698+
`implicit_clone::unsync::string::IString` implements `From<&Classes>`
698699
`implicit_clone::unsync::string::IString` implements `From<&implicit_clone::unsync::string::IString>`
699700
`implicit_clone::unsync::string::IString` implements `From<&str>`
700701
`implicit_clone::unsync::string::IString` implements `From<Arguments<'_>>`

packages/yew/src/html/classes.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,18 @@ impl<T: Into<Classes>, const SIZE: usize> From<[T; SIZE]> for Classes {
277277
}
278278
}
279279

280+
impl From<&Classes> for Classes {
281+
fn from(c: &Classes) -> Self {
282+
c.clone()
283+
}
284+
}
285+
286+
impl From<&Classes> for AttrValue {
287+
fn from(c: &Classes) -> Self {
288+
c.clone().into_prop_value()
289+
}
290+
}
291+
280292
impl PartialEq for Classes {
281293
fn eq(&self, other: &Self) -> bool {
282294
self.set.len() == other.set.len() && self.set.iter().eq(other.set.iter())

0 commit comments

Comments
 (0)