1+ use lol_html:: html_content:: ContentType as NativeContentType ;
12use lol_html:: html_content:: Element as NativeElement ;
3+
24use pyo3:: exceptions:: PyRuntimeError ;
35use pyo3:: prelude:: * ;
46
5- use crate :: { ContentType , HasNative , IntoNative , NativeRefWrap } ;
7+ use crate :: {
8+ ContentType , HasInner , HasNative , IntoNative , NativeBeforeAfter , NativeRefWrap , PyBeforeAfter ,
9+ } ;
610
711#[ pyclass( unsendable) ]
812pub struct Element {
@@ -21,6 +25,24 @@ impl Element {
2125 }
2226}
2327
28+ impl HasInner < NativeElement < ' static , ' static > > for Element {
29+ #[ inline]
30+ fn inner_native ( & mut self ) -> & mut NativeRefWrap < NativeElement < ' static , ' static > > {
31+ & mut self . inner
32+ }
33+ }
34+
35+ impl NativeBeforeAfter for lol_html:: html_content:: Element < ' static , ' static > {
36+ #[ inline]
37+ fn native_before ( & mut self , content : & str , ct : NativeContentType ) {
38+ self . before ( content, ct) ;
39+ }
40+ #[ inline]
41+ fn native_after ( & mut self , content : & str , ct : NativeContentType ) {
42+ self . after ( content, ct) ;
43+ }
44+ }
45+
2446#[ pymethods]
2547impl Element {
2648 #[ getter]
@@ -99,53 +121,37 @@ impl Element {
99121 }
100122
101123 #[ pyo3( signature = ( content, content_type=None ) ) ]
102-
103- pub fn prepend (
104- & mut self ,
105- content : & str ,
106- content_type : Option < ContentType > ,
107- ) -> PyResult < ( ) > {
124+ pub fn prepend ( & mut self , content : & str , content_type : Option < ContentType > ) -> PyResult < ( ) > {
108125 self . inner
109126 . get_mut ( ) ?
110127 . prepend ( content, content_type. into_native ( ) ) ;
111128 Ok ( ( ) )
112129 }
113130
114131 #[ pyo3( signature = ( content, content_type=None ) ) ]
115- pub fn append (
116- & mut self ,
117- content : & str ,
118- content_type : Option < ContentType > ,
119- ) -> PyResult < ( ) > {
132+ pub fn append ( & mut self , content : & str , content_type : Option < ContentType > ) -> PyResult < ( ) > {
120133 self . inner
121134 . get_mut ( ) ?
122135 . append ( content, content_type. into_native ( ) ) ;
123136 Ok ( ( ) )
124137 }
125138
126-
127139 #[ pyo3( signature = ( content, content_type=None ) ) ]
128- pub fn before (
129- & mut self ,
130- content : & str ,
131- content_type : Option < ContentType > ,
132- ) -> PyResult < ( ) > {
133- self . inner
134- . get_mut ( ) ?
135- . before ( content, content_type. into_native ( ) ) ;
136- Ok ( ( ) )
140+ pub fn before ( & mut self , content : & str , content_type : Option < ContentType > ) -> PyResult < ( ) > {
141+ <Self as PyBeforeAfter < NativeElement < ' static , ' static > > >:: before_impl (
142+ self ,
143+ content,
144+ content_type,
145+ )
137146 }
138147
139148 #[ pyo3( signature = ( content, content_type=None ) ) ]
140- pub fn after (
141- & mut self ,
142- content : & str ,
143- content_type : Option < ContentType > ,
144- ) -> PyResult < ( ) > {
145- self . inner
146- . get_mut ( ) ?
147- . after ( content, content_type. into_native ( ) ) ;
148- Ok ( ( ) )
149+ pub fn after ( & mut self , content : & str , content_type : Option < ContentType > ) -> PyResult < ( ) > {
150+ <Self as PyBeforeAfter < NativeElement < ' static , ' static > > >:: after_impl (
151+ self ,
152+ content,
153+ content_type,
154+ )
149155 }
150156
151157 #[ pyo3( signature = ( content, content_type=None ) ) ]
0 commit comments