xdb-parse 0.2.0

High-performance, zero-copy xdb IP geolocation parser (ip2region-compatible)
Documentation
//! Error types for the xdb-parse library.

use thiserror::Error;

/// All errors returned by xdb-parse operations.
///
/// Wraps I/O errors, parsing errors, invalid input, and corrupt data.
/// Uses `thiserror` for automatic [`std::fmt::Display`] and [`std::error::Error`] impls.
#[derive(Debug, Error)]
pub enum XdbError {
    /// The input string could not be parsed as an IP address or numeric value.
    #[error("Invalid IP: {0}")]
    InvalidIP(String),

    /// The xdb file version could not be determined.
    #[error("Invalid IP Version: {0}")]
    InvalidIPVersion(String),

    /// Region data in the xdb file is not valid UTF-8.
    #[error("Invalid UTF-8 in region data")]
    InvalidUtf8,

    /// Header parsing failed.
    #[error("Header Parse Error: {0}")]
    HeaderParseError(String),

    /// Index access out of range (corrupt or truncated file).
    #[error("RangeIndexOut:{0}")]
    RangeIndexOutError(String),

    /// Wraps [`std::net::AddrParseError`].
    #[error("AddrParseError: {0}")]
    AddrParseError(#[from] std::net::AddrParseError),

    /// Wraps [`std::num::ParseIntError`].
    #[error("ParseInt Error: {0}")]
    ParseIntError(#[from] std::num::ParseIntError),

    /// Wraps [`std::io::Error`].
    #[error("Io Error:{0}")]
    IoError(#[from] std::io::Error),

    /// Wraps [`std::array::TryFromSliceError`] — typically from corrupt data.
    #[error("Slice Error: {0}")]
    SliceError(#[from] std::array::TryFromSliceError),
}