pub struct Decoder { /* private fields */ }Expand description
Decoder of byte slices into strings.
If the encoding feature is enabled, the encoding is taken from the
encoding="..." pseudo-attribute of the XML declaration, or assumed to be
UTF-8 if there is no declaration or the encoding is unknown.
If the encoding feature is disabled, the decoder is always a UTF-8 decoder
and any XML declaration is ignored.
Implementations§
Source§impl Decoder
impl Decoder
Sourcepub const fn encoding(&self) -> Encoding
Available on crate feature encoding only.
pub const fn encoding(&self) -> Encoding
encoding only.Returns the encoding used by this decoder.
This encoding is used by decode.
Sourcepub fn decode<'b>(&self, bytes: &'b [u8]) -> Result<Cow<'b, str>, EncodingError>
pub fn decode<'b>(&self, bytes: &'b [u8]) -> Result<Cow<'b, str>, EncodingError>
Decodes the given bytes.
Without the encoding feature this decodes a UTF-8 slice regardless of any
XML declaration (and ignoring any byte-order mark). With the encoding
feature it decodes using the encoding declared in the XML, or UTF-8
otherwise.
Returns an error in case of malformed sequences in bytes.
Sourcepub fn decode_into(
&self,
bytes: &[u8],
buf: &mut String,
) -> Result<(), EncodingError>
pub fn decode_into( &self, bytes: &[u8], buf: &mut String, ) -> Result<(), EncodingError>
Like decode but writes into a pre-allocated buffer.