@@ -54,38 +54,38 @@ impl Decoder {
54
54
}
55
55
}
56
56
57
- #[ cfg( not( feature = "encoding" ) ) ]
58
- impl Decoder {
59
- /// Decodes a UTF8 slice regardless of XML declaration and ignoring BOM if
60
- /// it is present in the `bytes`.
61
- ///
62
- /// Returns an error in case of malformed sequences in the `bytes`.
63
- ///
64
- /// If you instead want to use XML declared encoding, use the `encoding` feature
65
- #[ inline]
66
- pub fn decode < ' b > ( & self , bytes : & ' b [ u8 ] ) -> Result < Cow < ' b , str > > {
67
- Ok ( Cow :: Borrowed ( std:: str:: from_utf8 ( bytes) ?) )
68
- }
69
- }
70
-
71
- #[ cfg( feature = "encoding" ) ]
72
57
impl Decoder {
73
58
/// Returns the `Reader`s encoding.
74
59
///
75
60
/// This encoding will be used by [`decode`].
76
61
///
77
62
/// [`decode`]: Self::decode
63
+ #[ cfg( feature = "encoding" ) ]
78
64
pub const fn encoding ( & self ) -> & ' static Encoding {
79
65
self . encoding
80
66
}
81
67
68
+ /// ## Without `encoding` feature
69
+ ///
70
+ /// Decodes an UTF-8 slice regardless of XML declaration and ignoring BOM
71
+ /// if it is present in the `bytes`.
72
+ ///
73
+ /// ## With `encoding` feature
74
+ ///
82
75
/// Decodes specified bytes using encoding, declared in the XML, if it was
83
76
/// declared there, or UTF-8 otherwise, and ignoring BOM if it is present
84
77
/// in the `bytes`.
85
78
///
79
+ /// ----
86
80
/// Returns an error in case of malformed sequences in the `bytes`.
87
81
pub fn decode < ' b > ( & self , bytes : & ' b [ u8 ] ) -> Result < Cow < ' b , str > > {
88
- decode ( bytes, self . encoding )
82
+ #[ cfg( not( feature = "encoding" ) ) ]
83
+ let decoded = Ok ( Cow :: Borrowed ( std:: str:: from_utf8 ( bytes) ?) ) ;
84
+
85
+ #[ cfg( feature = "encoding" ) ]
86
+ let decoded = decode ( bytes, self . encoding ) ;
87
+
88
+ decoded
89
89
}
90
90
}
91
91
0 commit comments