pub type Result<T = ()> = std::result::Result<T, Error>;
#[derive(Debug)]
#[non_exhaustive]
pub enum Error {
Index(u64),
#[cfg(feature = "disktree")]
Io(std::io::Error),
#[cfg(feature = "disktree")]
NotDisktree,
#[cfg(feature = "disktree")]
Version(u8),
#[cfg(feature = "disktree")]
InvalidTag(u8, u64),
#[cfg(feature = "disktree")]
Varint(u32),
#[cfg(feature = "disktree")]
Writer(Box<dyn std::error::Error + Send + Sync>),
}
#[cfg(feature = "disktree")]
impl std::convert::From<std::io::Error> for Error {
fn from(other: std::io::Error) -> Self {
Error::Io(other)
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Error::Index(_) => None,
#[cfg(feature = "disktree")]
Error::Io(inner) => inner.source(),
#[cfg(feature = "disktree")]
Error::NotDisktree => None,
#[cfg(feature = "disktree")]
Error::Version(_) => None,
#[cfg(feature = "disktree")]
Error::InvalidTag(_, _) => None,
#[cfg(feature = "disktree")]
Error::Varint(_) => None,
#[cfg(feature = "disktree")]
Error::Writer(inner) => inner.source(),
}
}
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Error::Index(bits) => write!(f, "raw u64 is not a valid H3 index: {bits}"),
#[cfg(feature = "disktree")]
Error::Io(io_error) => io_error.fmt(f),
#[cfg(feature = "disktree")]
Error::NotDisktree => {
write!(f, "file missing magic header")
}
#[cfg(feature = "disktree")]
Error::Version(version) => {
write!(f, "unsupported version, got {version}")
}
#[cfg(feature = "disktree")]
Error::InvalidTag(tag, pos) => {
write!(f, "invalid tag, got {tag}, pos {pos}")
}
#[cfg(feature = "disktree")]
Error::Varint(val) => {
write!(f, "byte sequence is not a valid varint, got {val}")
}
#[cfg(feature = "disktree")]
Error::Writer(writer_error) => {
write!(f, "provided writer returned an error, got {writer_error}")
}
}
}
}