9898 }
9999}
100100
101+ impl From < Comment > for Node {
102+ fn from ( comment : Comment ) -> Self {
103+ Self :: Comment ( comment)
104+ }
105+ }
106+
107+ impl From < Doctype > for Node {
108+ fn from ( doctype : Doctype ) -> Self {
109+ Self :: Doctype ( doctype)
110+ }
111+ }
112+
113+ impl From < Fragment > for Node {
114+ fn from ( fragment : Fragment ) -> Self {
115+ Self :: Fragment ( fragment)
116+ }
117+ }
118+
119+ impl From < Element > for Node {
120+ fn from ( element : Element ) -> Self {
121+ Self :: Element ( element)
122+ }
123+ }
124+
125+ impl From < Text > for Node {
126+ fn from ( text : Text ) -> Self {
127+ Self :: Text ( text)
128+ }
129+ }
130+
131+ impl From < UnsafeText > for Node {
132+ fn from ( text : UnsafeText ) -> Self {
133+ Self :: UnsafeText ( text)
134+ }
135+ }
136+
101137impl Display for Node {
102138 fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
103139 match & self {
@@ -139,21 +175,14 @@ impl Display for Comment {
139175 }
140176}
141177
142- impl From < String > for Comment {
143- fn from ( comment : String ) -> Self {
144- Self { comment }
145- }
146- }
147-
148- impl From < & str > for Comment {
149- fn from ( comment : & str ) -> Self {
150- comment. to_owned ( ) . into ( )
151- }
152- }
153-
154- impl From < Comment > for Node {
155- fn from ( comment : Comment ) -> Self {
156- Self :: Comment ( comment)
178+ impl < C > From < C > for Comment
179+ where
180+ C : Into < String > ,
181+ {
182+ fn from ( comment : C ) -> Self {
183+ Self {
184+ comment : comment. into ( ) ,
185+ }
157186 }
158187}
159188
@@ -179,21 +208,14 @@ impl Display for Doctype {
179208 }
180209}
181210
182- impl From < String > for Doctype {
183- fn from ( syntax : String ) -> Self {
184- Self { syntax }
185- }
186- }
187-
188- impl From < & str > for Doctype {
189- fn from ( syntax : & str ) -> Self {
190- syntax. to_owned ( ) . into ( )
191- }
192- }
193-
194- impl From < Doctype > for Node {
195- fn from ( doctype : Doctype ) -> Self {
196- Self :: Doctype ( doctype)
211+ impl < S > From < S > for Doctype
212+ where
213+ S : Into < String > ,
214+ {
215+ fn from ( syntax : S ) -> Self {
216+ Self {
217+ syntax : syntax. into ( ) ,
218+ }
197219 }
198220}
199221
@@ -223,12 +245,6 @@ impl Display for Fragment {
223245 }
224246}
225247
226- impl From < Fragment > for Node {
227- fn from ( fragment : Fragment ) -> Self {
228- Self :: Fragment ( fragment)
229- }
230- }
231-
232248/// An element.
233249///
234250/// ```html
@@ -296,12 +312,6 @@ impl Display for Element {
296312 }
297313}
298314
299- impl From < Element > for Node {
300- fn from ( element : Element ) -> Self {
301- Self :: Element ( element)
302- }
303- }
304-
305315/// A text node.
306316///
307317/// ```html
@@ -327,21 +337,12 @@ impl Display for Text {
327337 }
328338}
329339
330- impl From < String > for Text {
331- fn from ( text : String ) -> Self {
332- Self { text }
333- }
334- }
335-
336- impl From < & str > for Text {
337- fn from ( text : & str ) -> Self {
338- text. to_owned ( ) . into ( )
339- }
340- }
341-
342- impl From < Text > for Node {
343- fn from ( text : Text ) -> Self {
344- Self :: Text ( text)
340+ impl < T > From < T > for Text
341+ where
342+ T : Into < String > ,
343+ {
344+ fn from ( text : T ) -> Self {
345+ Self { text : text. into ( ) }
345346 }
346347}
347348
@@ -364,21 +365,12 @@ impl Display for UnsafeText {
364365 }
365366}
366367
367- impl From < String > for UnsafeText {
368- fn from ( text : String ) -> Self {
369- Self { text }
370- }
371- }
372-
373- impl From < & str > for UnsafeText {
374- fn from ( text : & str ) -> Self {
375- text. to_owned ( ) . into ( )
376- }
377- }
378-
379- impl From < UnsafeText > for Node {
380- fn from ( text : UnsafeText ) -> Self {
381- Self :: UnsafeText ( text)
368+ impl < T > From < T > for UnsafeText
369+ where
370+ T : Into < String > ,
371+ {
372+ fn from ( text : T ) -> Self {
373+ Self { text : text. into ( ) }
382374 }
383375}
384376
0 commit comments