Module geo
Available on crate feature
net only.Expand description
IP geolocation: map an IpAddr to location data.
This module provides a dependency-free, zero-copy reader for the
MaxMind DB (.mmdb) binary format — the de-facto standard shipped by
MaxMind (GeoLite2 / GeoIP2), DB-IP and others — together with a minimal
writer used to synthesise test fixtures (and, in a later phase, to
compile other inputs such as CSV into the same in-memory representation).
The on-disk format is documented in
rama-net/specifications/geoip/MaxMind-DB-spec.md.
§Design
- Zero-copy by default.
MmdbReader::lookupreturns an opaque borrowing view (GeoLocationRef) that decodes fields lazily from the backing buffer without allocating. CallGeoLocationRef::to_ownedto obtain an owned,'staticGeoLocationsuitable for storing inrama_core::extensionsor serialising. - Minimal memory. The database is held once as a shared buffer and never fully materialised; a lookup walks a handful of tree nodes and decodes only the matched record.
- No third-party dependencies. The reader and writer use
stdonly.
Modules§
- mmdb
- MaxMind DB (
.mmdb) reader and minimal writer.
Structs§
- AsOrg
- Autonomous system information (typically from an ASN database).
- Coordinates
- Geographic coordinates and associated location metadata.
- CsvGeo
Record - A CSV row mapped to an inclusive IP range and its geolocation.
- GeoLocation
- Owned,
'staticgeolocation data for a single IP address. - GeoLocation
Ref - A borrowing, zero-copy view over a single decoded geolocation record.
- IpGeoDb
- A collection of labelled IP geolocation sources, queried together.
- IpGeo
DbBuilder - Builder for
IpGeoDb. - IpGeo
Info - Resolved IP geolocation, suitable for storing in
rama_core::extensions. - IpGeo
Source Result - A single source’s merged geolocation result.
- Metadata
- Parsed metadata describing a MaxMind DB.
- Mmdb
Builder - A builder for MaxMind DB byte images.
- Mmdb
Reader - A zero-copy reader over a MaxMind DB.
- Subdivision
- A subdivision (state / region / province) as recorded in a database.
- Time
Zone Name - A time-zone value as recorded by the geolocation provider, stored verbatim.
Enums§
- CsvError
- Error while compiling CSV into a MaxMind DB.
- GeoIp
Error - Error returned while loading or querying an IP geolocation database.
- Ip2Location
Lite - IP2Location LITE database layout.
- IpVersion
- The IP version of the addresses a database indexes.
- Mmdb
Write Error - Error returned while building or serialising a MaxMind DB.
- Record
Size - The number of bits in each search-tree record. The format only defines 24, 28 and 32; a node always holds two records.
Constants§
- RAMA_
IP_ GEO_ DB_ ENV - Name of the environment variable parsed by
IpGeoDb::from_env.
Functions§
- compile_
csv - Compile range-based CSV into an in-memory
MmdbReader. - compile_
csv_ into - Compile range-based CSV into an existing
MmdbBuilder. - compile_
ip2location_ lite - Compile an IP2Location LITE CSV export into an in-memory
MmdbReader. - compile_
ip2location_ lite_ to_ file - Compile an IP2Location LITE CSV export and write the database to
path, streaming it to disk.