use std::borrow::Cow;
use std::error::Error;
use std::fmt;
use std::fmt::Display;
use std::fmt::Formatter;
#[cfg_attr(not(windows), allow(dead_code))]
#[derive(Debug, Eq, PartialEq)]
pub(super) enum EncodingError {
Byte(u8),
CodePoint(u32),
End(),
}
impl EncodingError {
fn position(&self) -> Cow<'_, str> {
match self {
EncodingError::Byte(byte) => {
Cow::Owned(format!("byte b'\\x{:02X}'", byte))
}
EncodingError::CodePoint(code_point) => {
Cow::Owned(format!("code point U+{:04X}", code_point))
}
EncodingError::End() => Cow::Borrowed("end of string"),
}
}
}
impl Display for EncodingError {
fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
write!(
formatter,
"os_str_bytes: byte sequence is not representable in the platform \
encoding; error at {}",
self.position(),
)
}
}
impl Error for EncodingError {}