scufflecloud_geo_ip/resolver.rs
1use maxminddb::MaxMindDbError;
2
3pub struct GeoIpResolver {
4 reader: maxminddb::Reader<Vec<u8>>,
5}
6
7impl GeoIpResolver {
8 pub fn new_from_data(data: Vec<u8>) -> Result<Self, MaxMindDbError> {
9 let reader = maxminddb::Reader::from_source(data)?;
10 Ok(Self { reader })
11 }
12
13 pub fn lookup<'a, T: serde::Deserialize<'a>>(&'a self, ip: std::net::IpAddr) -> Result<Option<T>, MaxMindDbError> {
14 self.reader.lookup::<T>(ip)
15 }
16}