11use super :: node:: Node ;
22#[ cfg( feature = "source-span" ) ]
33use super :: span:: SourceSpan ;
4- use crate :: VecSet ;
54use crate :: dom:: vecmap:: VecMap ;
5+ use crate :: { Attribute , VecSet } ;
6+ use ownable:: { IntoOwned , ToBorrowed , ToOwned } ;
67use serde:: Serialize ;
8+ use std:: borrow:: Cow ;
79use std:: default:: Default ;
810
911/// Normal: `<div></div>` or Void: `<meta/>`and `<meta>`
@@ -17,48 +19,49 @@ pub enum ElementVariant {
1719 Void ,
1820}
1921
20- pub type Attributes = VecMap < String , Option < String > > ;
22+ pub type Attributes < ' a > = VecMap < Cow < ' a , str > , Option < Attribute < ' a > > > ;
2123
2224/// Most of the parsed html nodes are elements, except for text
23- #[ derive( Debug , Clone , Serialize , PartialEq ) ]
25+ #[ derive( Debug , Serialize , PartialEq , IntoOwned , ToBorrowed , ToOwned ) ]
2426#[ serde( rename_all = "camelCase" ) ]
25- pub struct Element {
27+ pub struct Element < ' a > {
2628 /// The id of the element
2729 #[ serde( skip_serializing_if = "Option::is_none" ) ]
28- pub id : Option < String > ,
30+ pub id : Option < Attribute < ' a > > ,
2931
3032 /// The name / tag of the element
31- pub name : String ,
33+ pub name : Cow < ' a , str > ,
3234
3335 /// The element variant, if it is of type void or not
36+ #[ ownable( clone) ]
3437 pub variant : ElementVariant ,
3538
3639 /// All of the elements attributes, except id and class
3740 #[ serde( skip_serializing_if = "VecMap::is_empty" ) ]
38- pub attributes : Attributes ,
41+ pub attributes : Attributes < ' a > ,
3942
4043 /// All of the elements classes
4144 #[ serde( skip_serializing_if = "VecSet::is_empty" ) ]
42- pub classes : VecSet < String > ,
45+ pub classes : VecSet < Attribute < ' a > > ,
4346
4447 /// All of the elements child nodes
4548 #[ serde( skip_serializing_if = "Vec::is_empty" ) ]
46- pub children : Vec < Node > ,
49+ pub children : Vec < Node < ' a > > ,
4750
4851 #[ cfg( feature = "source-span" ) ]
4952 /// Span of the element in the parsed source
5053 #[ serde( skip) ]
51- pub source_span : SourceSpan ,
54+ pub source_span : SourceSpan < ' a > ,
5255}
5356
54- impl Default for Element {
57+ impl Default for Element < ' static > {
5558 fn default ( ) -> Self {
5659 Self {
5760 id : None ,
58- name : "" . to_string ( ) ,
61+ name : "" . into ( ) ,
5962 variant : ElementVariant :: Void ,
60- classes : VecSet :: default ( ) ,
61- attributes : VecMap :: default ( ) ,
63+ classes : Default :: default ( ) ,
64+ attributes : Default :: default ( ) ,
6265 children : vec ! [ ] ,
6366 #[ cfg( feature = "source-span" ) ]
6467 source_span : SourceSpan :: default ( ) ,
0 commit comments