pub struct DecodedText { /* private fields */ }Expand description
The result of decoding a byte stream: either recovered text in a known TextEncoding, or the
original bytes preserved verbatim because they could not be decoded.
Construct one with DecodedText::decode; it never loses data and DecodedText::encode
reproduces the input.
Implementations§
Source§impl DecodedText
impl DecodedText
Sourcepub fn decode(bytes: &[u8]) -> Self
pub fn decode(bytes: &[u8]) -> Self
Decode bytes, sniffing a leading byte-order mark to pick the encoding. Valid UTF-8 or
UTF-16 is recovered as text; anything that fails to decode is preserved verbatim with an
OpaqueReason. Never fails and never loses data.
Sourcepub fn encoding(&self) -> TextEncoding
pub fn encoding(&self) -> TextEncoding
The encoding this text was decoded as, or TextEncoding::OpaqueBytes when the input could
not be decoded.
Sourcepub fn as_str(&self) -> Option<&str>
pub fn as_str(&self) -> Option<&str>
The decoded text, or None when the input was kept opaque (see Self::opaque_reason).
Sourcepub fn opaque_reason(&self) -> Option<OpaqueReason>
pub fn opaque_reason(&self) -> Option<OpaqueReason>
Why the input was kept opaque, or None when it decoded as text.
Trait Implementations§
Source§impl Clone for DecodedText
impl Clone for DecodedText
Source§fn clone(&self) -> DecodedText
fn clone(&self) -> DecodedText
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for DecodedText
impl Debug for DecodedText
impl Eq for DecodedText
Source§impl PartialEq for DecodedText
impl PartialEq for DecodedText
impl StructuralPartialEq for DecodedText
Auto Trait Implementations§
impl Freeze for DecodedText
impl RefUnwindSafe for DecodedText
impl Send for DecodedText
impl Sync for DecodedText
impl Unpin for DecodedText
impl UnsafeUnpin for DecodedText
impl UnwindSafe for DecodedText
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more