Expand description
A high-performance, zero-copy parser and query engine for xdb IP geolocation database files (ip2region-compatible format).
Supports both IPv4 and IPv6 lookup via an optimized two-level binary search.
§Quick start
use xdb_parse::{load_file, search_ip};
let data = load_file("./assets/ip2region_v4.xdb".into())?;
let location = search_ip("73.24.63.66", &data)?;
println!("{}", location);§Flexible input
search_ip accepts any type that implements IntoIpAddr:
use xdb_parse::{load_file, search_ip};
let data = load_file("./assets/ip2region_v4.xdb".into())?;
// &str or String
search_ip("73.24.63.66", &data)?;
// raw u32 (fastest IPv4 path)
search_ip(0x4918_3F42u32, &data)?;
// IpAddr from socket
search_ip("::1".parse::<std::net::IpAddr>()?, &data)?;§Performance
All search functions return &str borrowing from the loaded buffer —
zero allocation per query. For the fastest path, use
search_by_uint / search_by_u128 to skip trait dispatch.
§Thread safety
The loaded Vec<u8> is Send + Sync. Wrap it in Arc to share across threads:
use std::sync::Arc;
use xdb_parse::{load_file, search_ip};
let data = Arc::new(load_file("./assets/ip2region_v6.xdb".into())?);
let handle = std::thread::spawn({
let data = Arc::clone(&data);
move || search_ip("::1", &data).unwrap()
});Re-exports§
pub use ip::IntoIpAddr;pub use search::search_by_ipaddr;pub use search::search_by_u128;pub use search::search_by_uint;pub use search::search_ip;pub use xdb::Header;pub use xdb::IpVersion;pub use xdb::detect_version;
Modules§
- error
- Error types for the xdb-parse library.
- ip
- search
- IP geolocation lookup functions.
- xdb
- Xdb file metadata: header parsing and IP version detection.
Functions§
- load_
file - Load an xdb database file into memory.