pub struct GeoLocator { /* private fields */ }Expand description
MaxMind GeoLite2/GeoIP2 database reader.
Wraps the mmdb reader in an Arc so cloning is cheap. Register a
GeoLocator in the service registry and extract it in handlers via
Service<GeoLocator>.
Implementations§
Source§impl GeoLocator
impl GeoLocator
Sourcepub fn from_config(config: &GeolocationConfig) -> Result<Self>
pub fn from_config(config: &GeolocationConfig) -> Result<Self>
Open the mmdb file specified in config and return a ready locator.
§Errors
Returns Error::internal when mmdb_path is
empty or the file cannot be opened.
Sourcepub fn lookup(&self, ip: IpAddr) -> Result<Location>
pub fn lookup(&self, ip: IpAddr) -> Result<Location>
Look up ip in the MaxMind database and return geolocation data.
Returns a Location with all-None fields when the IP is not found
in the database (private ranges, loopback addresses, etc.).
§Errors
Returns Error::internal when the database
lookup or record decoding fails.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for GeoLocator
impl RefUnwindSafe for GeoLocator
impl Send for GeoLocator
impl Sync for GeoLocator
impl Unpin for GeoLocator
impl UnsafeUnpin for GeoLocator
impl UnwindSafe for GeoLocator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more