Skip to content

Commit b8f4b11

Browse files
Mingundralley
authored andcommitted
Merge Decoder methods to avoid wrong remark about necessarily of encoding feature for them in the doc
This also allow to show doc for both variants of the methods
1 parent 59c5d4e commit b8f4b11

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

src/encoding.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,38 +54,38 @@ impl Decoder {
5454
}
5555
}
5656

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")]
7257
impl Decoder {
7358
/// Returns the `Reader`s encoding.
7459
///
7560
/// This encoding will be used by [`decode`].
7661
///
7762
/// [`decode`]: Self::decode
63+
#[cfg(feature = "encoding")]
7864
pub const fn encoding(&self) -> &'static Encoding {
7965
self.encoding
8066
}
8167

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+
///
8275
/// Decodes specified bytes using encoding, declared in the XML, if it was
8376
/// declared there, or UTF-8 otherwise, and ignoring BOM if it is present
8477
/// in the `bytes`.
8578
///
79+
/// ----
8680
/// Returns an error in case of malformed sequences in the `bytes`.
8781
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
8989
}
9090
}
9191

0 commit comments

Comments
 (0)