@@ -64,65 +64,76 @@ impl Into<JsValue> for AttributeValue {
64
64
}
65
65
}
66
66
67
- impl From < String > for AttributeValue {
68
- fn from ( s : String ) -> Self {
69
- AttributeValue :: String ( s)
67
+ mod from_impls {
68
+ //! These `From` implementations are used by the `html-macro` to convert an arbitrary expression
69
+ //! into an [`AttributeValue`].
70
+ //! Relying on the `From` impl allows us to create an `AttributeValue` without needing the
71
+ //! `AttributeValue` type to be in scope. This means that the generated macro code does not
72
+ //! require `AttributeValue` to be in scope.
73
+ //! To find this use case, search for `#value.into()` within the `crates/html-macro` crate.
74
+
75
+ use super :: * ;
76
+
77
+ impl From < String > for AttributeValue {
78
+ fn from ( s : String ) -> Self {
79
+ AttributeValue :: String ( s)
80
+ }
70
81
}
71
- }
72
82
73
- impl From < & String > for AttributeValue {
74
- fn from ( s : & String ) -> Self {
75
- AttributeValue :: String ( s. to_string ( ) )
83
+ impl From < & String > for AttributeValue {
84
+ fn from ( s : & String ) -> Self {
85
+ AttributeValue :: String ( s. to_string ( ) )
86
+ }
76
87
}
77
- }
78
88
79
- impl From < & str > for AttributeValue {
80
- fn from ( s : & str ) -> Self {
81
- AttributeValue :: String ( s. to_string ( ) )
89
+ impl From < & str > for AttributeValue {
90
+ fn from ( s : & str ) -> Self {
91
+ AttributeValue :: String ( s. to_string ( ) )
92
+ }
82
93
}
83
- }
84
94
85
- impl < S : AsRef < str > , const N : usize > From < [ S ; N ] > for AttributeValue {
86
- fn from ( vals : [ S ; N ] ) -> Self {
87
- let mut combined = "" . to_string ( ) ;
95
+ impl < S : AsRef < str > , const N : usize > From < [ S ; N ] > for AttributeValue {
96
+ fn from ( vals : [ S ; N ] ) -> Self {
97
+ let mut combined = "" . to_string ( ) ;
88
98
89
- for ( idx, val) in vals. iter ( ) . enumerate ( ) {
90
- if idx != 0 {
91
- combined += " " ;
99
+ for ( idx, val) in vals. iter ( ) . enumerate ( ) {
100
+ if idx != 0 {
101
+ combined += " " ;
102
+ }
103
+
104
+ combined += val. as_ref ( ) ;
92
105
}
93
106
94
- combined += val . as_ref ( ) ;
107
+ AttributeValue :: String ( combined )
95
108
}
96
-
97
- AttributeValue :: String ( combined)
98
109
}
99
- }
100
110
101
- impl < S : AsRef < str > > From < Vec < S > > for AttributeValue {
102
- fn from ( vals : Vec < S > ) -> Self {
103
- let mut combined = "" . to_string ( ) ;
111
+ impl < S : AsRef < str > > From < Vec < S > > for AttributeValue {
112
+ fn from ( vals : Vec < S > ) -> Self {
113
+ let mut combined = "" . to_string ( ) ;
104
114
105
- for ( idx, val) in vals. iter ( ) . enumerate ( ) {
106
- if idx != 0 {
107
- combined += " " ;
115
+ for ( idx, val) in vals. iter ( ) . enumerate ( ) {
116
+ if idx != 0 {
117
+ combined += " " ;
118
+ }
119
+
120
+ combined += val. as_ref ( ) ;
108
121
}
109
122
110
- combined += val . as_ref ( ) ;
123
+ AttributeValue :: String ( combined )
111
124
}
112
-
113
- AttributeValue :: String ( combined)
114
125
}
115
- }
116
126
117
- impl From < bool > for AttributeValue {
118
- fn from ( b : bool ) -> Self {
119
- AttributeValue :: Bool ( b)
127
+ impl From < bool > for AttributeValue {
128
+ fn from ( b : bool ) -> Self {
129
+ AttributeValue :: Bool ( b)
130
+ }
120
131
}
121
- }
122
132
123
- impl From < & bool > for AttributeValue {
124
- fn from ( b : & bool ) -> Self {
125
- AttributeValue :: Bool ( * b)
133
+ impl From < & bool > for AttributeValue {
134
+ fn from ( b : & bool ) -> Self {
135
+ AttributeValue :: Bool ( * b)
136
+ }
126
137
}
127
138
}
128
139
0 commit comments