pub struct MalformedError(/* private fields */);
Expand description
The error type reported by DecodingReader
and EncodingWriter
when they encounter a
malformed byte sequence.
DecodingReader
reports this error when its decoder encounters a malformed byte sequence.
EncodingWriter
reports this error when an invalid UTF-8 sequence is supplied as input.
The Read
and Write
implementations of DecodingReader
and EncodingWriter
,
respectively, report this error in the form of std::io::Error
wrapping an instance of this
type. Callers need to unwrap and downcast the inner error of a reported error, which can be
shortcut by wrapped_in
.
§Examples
use encoding_rs::SHIFT_JIS;
use encoding_rs_rw::{DecodingReader, MalformedError};
use std::io::Read as _;
let src: &[u8] = &[227, 89, 151, 0xff, 144, 175];
let mut reader = DecodingReader::new(src, SHIFT_JIS.new_decoder());
let mut dst = String::new();
while let Err(io_error) = reader.read_to_string(&mut dst) {
if MalformedError::wrapped_in(&io_error).is_some() {
// insert replacement character (U+FFFD) and continue
dst.push('�');
} else {
panic!("found other error than MalformedError: {}", io_error);
}
}
assert_eq!(dst, "綺�星");
Implementations§
Source§impl MalformedError
impl MalformedError
Sourcepub fn wrapped_in(io_error: &Error) -> Option<&Self>
pub fn wrapped_in(io_error: &Error) -> Option<&Self>
Returns a reference to the MalformedError
value wrapped by a std::io::Error
if it
contains an inner error whose type is MalformedError
, or returns None
otherwise.
Trait Implementations§
Source§impl Clone for MalformedError
impl Clone for MalformedError
Source§fn clone(&self) -> MalformedError
fn clone(&self) -> MalformedError
Returns a duplicate of the value. Read more
1.0.0 · 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 MalformedError
impl Debug for MalformedError
Source§impl Display for MalformedError
impl Display for MalformedError
Source§impl Error for MalformedError
impl Error for MalformedError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
Auto Trait Implementations§
impl Freeze for MalformedError
impl RefUnwindSafe for MalformedError
impl Send for MalformedError
impl Sync for MalformedError
impl Unpin for MalformedError
impl UnwindSafe for MalformedError
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