pub struct Decoder { /* private fields */ }
Expand description
Decoder of byte slices into strings.
If feature encoding
is enabled, this encoding taken from the "encoding"
XML declaration or assumes UTF-8, if XML has no declaration, encoding
key is not defined or contains unknown encoding.
The library supports any UTF-8 compatible encodings that crate encoding_rs
is supported. UTF-16 and ISO-2022-JP are not supported at the present.
If feature encoding
is disabled, the decoder is always UTF-8 decoder:
any XML declarations are ignored.
Implementations§
Source§impl Decoder
impl Decoder
Sourcepub const fn encoding(&self) -> &'static Encoding
Available on crate feature encoding
only.
pub const fn encoding(&self) -> &'static Encoding
encoding
only.Returns the Reader
s encoding.
This encoding will be 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>
§Without encoding
feature
Decodes an UTF-8 slice regardless of XML declaration and ignoring BOM
if it is present in the bytes
.
§With encoding
feature
Decodes specified bytes using encoding, declared in the XML, if it was
declared there, or UTF-8 otherwise, and ignoring BOM if it is present
in the bytes
.
Returns an error in case of malformed sequences in the 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 using a pre-allocated buffer.