#[cfg(feature = "std")]
mod csv;
#[cfg(feature = "std")]
pub use csv::{
CsvError, CsvGeoRecord, Ip2LocationLite, compile_csv, compile_csv_into,
compile_ip2location_lite, compile_ip2location_lite_to_file,
};
#[cfg(feature = "std")]
mod db;
#[cfg(feature = "std")]
pub use db::{IpGeoDb, IpGeoDbBuilder, IpGeoInfo, IpGeoSourceResult, RAMA_IP_GEO_DB_ENV};
mod location;
pub use location::{AsOrg, Coordinates, GeoLocation, GeoLocationRef, Subdivision, TimeZoneName};
pub mod mmdb;
pub use mmdb::{IpVersion, Metadata, MmdbReader, RecordSize};
#[cfg(feature = "std")]
pub use mmdb::{MmdbBuilder, MmdbWriteError};
use core::fmt;
use crate::std::boxed::Box;
#[derive(Debug)]
#[non_exhaustive]
pub enum GeoIpError {
MissingMetadataMarker,
Corrupt(&'static str),
Unsupported(&'static str),
#[cfg(feature = "std")]
Io(std::io::Error),
InvalidConfig(Box<str>),
Source {
path: Box<str>,
error: Box<Self>,
},
}
impl fmt::Display for GeoIpError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::MissingMetadataMarker => {
f.write_str("mmdb: metadata marker not found (not a MaxMind DB or truncated)")
}
Self::Corrupt(why) => write!(f, "mmdb: corrupt database: {why}"),
Self::Unsupported(why) => write!(f, "mmdb: unsupported database: {why}"),
#[cfg(feature = "std")]
Self::Io(err) => write!(f, "mmdb: i/o error: {err}"),
Self::InvalidConfig(why) => write!(f, "geoip: invalid configuration: {why}"),
Self::Source { path, error } => {
write!(f, "geoip: failed to load source {path:?}: {error}")
}
}
}
}
impl core::error::Error for GeoIpError {
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
match self {
#[cfg(feature = "std")]
Self::Io(err) => Some(err),
Self::Source { error, .. } => Some(error),
_ => None,
}
}
}
#[cfg(feature = "std")]
impl From<std::io::Error> for GeoIpError {
fn from(err: std::io::Error) -> Self {
Self::Io(err)
}
}