Skip to main content

Module geo

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::lookup returns an opaque borrowing view (GeoLocationRef) that decodes fields lazily from the backing buffer without allocating. Call GeoLocationRef::to_owned to obtain an owned, 'static GeoLocation suitable for storing in rama_core::extensions or 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 std only.

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.
CsvGeoRecord
A CSV row mapped to an inclusive IP range and its geolocation.
GeoLocation
Owned, 'static geolocation data for a single IP address.
GeoLocationRef
A borrowing, zero-copy view over a single decoded geolocation record.
IpGeoDb
A collection of labelled IP geolocation sources, queried together.
IpGeoDbBuilder
Builder for IpGeoDb.
IpGeoInfo
Resolved IP geolocation, suitable for storing in rama_core::extensions.
IpGeoSourceResult
A single source’s merged geolocation result.
Metadata
Parsed metadata describing a MaxMind DB.
MmdbBuilder
A builder for MaxMind DB byte images.
MmdbReader
A zero-copy reader over a MaxMind DB.
Subdivision
A subdivision (state / region / province) as recorded in a database.
TimeZoneName
A time-zone value as recorded by the geolocation provider, stored verbatim.

Enums§

CsvError
Error while compiling CSV into a MaxMind DB.
GeoIpError
Error returned while loading or querying an IP geolocation database.
Ip2LocationLite
IP2Location LITE database layout.
IpVersion
The IP version of the addresses a database indexes.
MmdbWriteError
Error returned while building or serialising a MaxMind DB.
RecordSize
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.