@@ -255,3 +255,44 @@ impl<'a> From<StartElementBuilder<'a>> for XmlEvent<'a> {
255255 }
256256 }
257257}
258+
259+ impl < ' a > TryFrom < & ' a crate :: reader:: XmlEvent > for XmlEvent < ' a > {
260+ type Error = ( ) ;
261+
262+ fn try_from ( event : & crate :: reader:: XmlEvent ) -> Result < XmlEvent < ' _ > , Self :: Error > {
263+ match event {
264+ crate :: reader:: XmlEvent :: StartDocument {
265+ version,
266+ encoding,
267+ standalone,
268+ } => Ok ( XmlEvent :: StartDocument {
269+ version : version. clone ( ) ,
270+ encoding : Some ( & encoding) ,
271+ standalone : standalone. clone ( ) ,
272+ } ) ,
273+ crate :: reader:: XmlEvent :: EndDocument => Err ( ( ) ) ,
274+ crate :: reader:: XmlEvent :: ProcessingInstruction { name, data } => {
275+ Ok ( XmlEvent :: ProcessingInstruction {
276+ name : & name,
277+ data : data. as_deref ( ) ,
278+ } )
279+ }
280+ crate :: reader:: XmlEvent :: StartElement {
281+ name,
282+ attributes,
283+ namespace,
284+ } => Ok ( XmlEvent :: StartElement {
285+ name : name. borrow ( ) ,
286+ attributes : Cow :: Owned ( attributes. iter ( ) . map ( |attr| attr. borrow ( ) ) . collect ( ) ) ,
287+ namespace : namespace. borrow ( ) ,
288+ } ) ,
289+ crate :: reader:: XmlEvent :: EndElement { name } => Ok ( XmlEvent :: EndElement {
290+ name : Some ( name. borrow ( ) ) ,
291+ } ) ,
292+ crate :: reader:: XmlEvent :: CData ( chars) => Ok ( XmlEvent :: CData ( chars) ) ,
293+ crate :: reader:: XmlEvent :: Comment ( chars) => Ok ( XmlEvent :: Comment ( chars) ) ,
294+ crate :: reader:: XmlEvent :: Characters ( chars) => Ok ( XmlEvent :: Characters ( chars) ) ,
295+ crate :: reader:: XmlEvent :: Whitespace ( chars) => Ok ( XmlEvent :: Characters ( chars) ) ,
296+ }
297+ }
298+ }
0 commit comments