use super::{FromHexError, FromHexErrorKind};
impl core::fmt::Display for FromHexErrorKind {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
match self {
FromHexErrorKind::UnexpectedCharacter(c) => write!(f, "unexpected character {c}"),
FromHexErrorKind::UnexpectedByte(b) => write!(f, "unexpected byte 0x{b:02x}"),
FromHexErrorKind::Eof => write!(f, "unexpected end of input"),
FromHexErrorKind::OutputBufferTooShort => write!(f, "output buffer is too short"),
}
}
}
impl core::fmt::Display for FromHexError {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
write!(
f,
"error converting from hex: {} at position {}",
self.kind, self.position
)
}
}
#[cfg(feature = "std")]
impl std::error::Error for FromHexError {}
pub fn has_0x_prefix(s: &str) -> bool {
s.starts_with("0x")
}
pub fn has_0x_prefix_ascii(buf: &[u8]) -> bool {
buf.starts_with(b"0x")
}