@@ -21,10 +21,14 @@ use crate::{xml_namespace_from_resolve_result, HasQuickXmlAlternative, OwnedQuic
21
21
22
22
/// Errors that can occur when using this crate.
23
23
#[ derive( Debug , thiserror:: Error ) ]
24
+ #[ non_exhaustive]
24
25
pub enum Error {
25
26
/// Error from the `quick-xml` crate.
26
27
#[ error( "Quick XML error: {0}" ) ]
27
28
QuickXml ( #[ from] quick_xml:: Error ) ,
29
+ /// Error from the `quick-xml` crate when decoding references.
30
+ #[ error( "Encoding error: {0}" ) ]
31
+ EncodingError ( #[ from] quick_xml:: encoding:: EncodingError ) ,
28
32
/// Error from the `quick-xml` crate when handling attributes.
29
33
#[ error( "Attribute error: {0}" ) ]
30
34
AttrError ( #[ from] quick_xml:: events:: attributes:: AttrError ) ,
@@ -838,6 +842,36 @@ impl<'de> XmlText<'de> for DataWithD<'_, BytesText<'de>> {
838
842
}
839
843
}
840
844
845
+ impl < ' de > XmlText < ' de > for DataWithD < ' _ , Cow < ' de , str > > {
846
+ type DeserializeContext < ' a >
847
+ = & ' a Deserializer < ' a >
848
+ where
849
+ Self : ' a ;
850
+
851
+ fn into_bytes ( self ) -> Cow < ' de , [ u8 ] > {
852
+ match self . data {
853
+ Cow :: Borrowed ( s) => Cow :: Borrowed ( s. as_bytes ( ) ) ,
854
+ Cow :: Owned ( s) => Cow :: Owned ( s. into_bytes ( ) ) ,
855
+ }
856
+ }
857
+
858
+ fn as_bytes ( & self ) -> & [ u8 ] {
859
+ self . data . as_bytes ( )
860
+ }
861
+
862
+ fn into_string ( self ) -> Cow < ' de , str > {
863
+ self . data
864
+ }
865
+
866
+ fn as_str ( & self ) -> & str {
867
+ self . data . as_ref ( )
868
+ }
869
+
870
+ fn context ( & self ) -> Self :: DeserializeContext < ' _ > {
871
+ self . deserializer
872
+ }
873
+ }
874
+
841
875
impl < ' de > XmlCData < ' de > for DataWithD < ' _ , BytesCData < ' de > > {
842
876
type DeserializeContext < ' a >
843
877
= & ' a Deserializer < ' a >
@@ -1045,6 +1079,9 @@ impl<'r> xmlity::Deserializer<'r> for &mut Deserializer<'r> {
1045
1079
Event :: PI ( bytes_pi) => visitor. visit_pi ( DataWithD :: new ( bytes_pi, self ) ) ,
1046
1080
Event :: DocType ( bytes_text) => visitor. visit_doctype ( DataWithD :: new ( bytes_text, self ) ) ,
1047
1081
Event :: Eof => Err ( Error :: custom ( "Unexpected EOF" ) ) ,
1082
+ Event :: GeneralRef ( bytes_ref) => {
1083
+ visitor. visit_text ( DataWithD :: new ( bytes_ref. decode ( ) ?, self ) )
1084
+ }
1048
1085
}
1049
1086
}
1050
1087
0 commit comments