Skip to content

Commit cbe95f5

Browse files
committed
reinit
1 parent 9cdd8cc commit cbe95f5

File tree

13 files changed

+863
-781
lines changed

13 files changed

+863
-781
lines changed

Cargo.toml

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,38 @@
11
[package]
22
name = "geoip2"
3-
version = "0.1.0"
3+
version = "0.0.1"
44
authors = ["IncSW <dev@incsw.in>"]
5+
description = "Library for reading MaxMind DB format used by GeoIP2 and GeoLite2"
6+
readme = "README.md"
7+
keywords = ["MaxMind", "GeoIP2", "GeoIP", "geolocation", "ip"]
8+
categories = ["database", "network-programming"]
9+
homepage = "https://github.com/IncSW/geoip2-rs"
10+
documentation = "https://docs.rs/geoip2"
11+
repository = "https://github.com/IncSW/geoip2-rs"
12+
license = "MIT"
513
edition = "2018"
14+
exclude = ["testdata"]
615

716
[dependencies]
8-
maxminddb = "0.15"
17+
geoip2-codegen = "0.0.1"
18+
19+
[workspace]
20+
members = [".", "codegen"]
21+
22+
[patch.crates-io]
23+
geoip2-codegen = { path = "codegen" }
24+
25+
[dev-dependencies]
26+
maxminddb = "0.21.0"
27+
28+
[profile.release]
29+
lto = "fat"
30+
codegen-units = 1
31+
opt-level = 3
32+
panic = "abort"
33+
34+
[[test]]
35+
name = "geoip"
36+
37+
[[bench]]
38+
name = "geoip"

README.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,38 @@
1-
WIP
1+
[![crates.io](https://img.shields.io/crates/v/geoip2?label=latest)](https://crates.io/crates/geoip2)
2+
[![Documentation](https://docs.rs/geoip2/badge.svg?version=0.0.1)](https://docs.rs/geoip2/0.0.1)
3+
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE)
4+
[![Dependency Status](https://deps.rs/crate/geoip2/0.0.1/status.svg)](https://deps.rs/crate/geoip2/0.0.1)
5+
![downloads](https://img.shields.io/crates/d/geoip2.svg)
6+
7+
# GeoIP2 Reader for Rust
8+
9+
This library reads MaxMind GeoIP2 databases.
10+
11+
## Usage
12+
13+
```toml
14+
[dependencies]
15+
geoip2 = "0.0.1"
16+
```
17+
18+
See [examples/lookup.rs](examples/lookup.rs) for a basic example.
19+
20+
## Performance
21+
22+
cargo 1.56.0-nightly, Intel i7-7700
23+
24+
### [IncSW/geoip2-rs](https://github.com/IncSW/geoip2-rs)
25+
```
26+
city 1,189 ns/iter (+/- 73)
27+
country 553 ns/iter (+/- 43)
28+
```
29+
30+
### [oschwald/maxminddb-rust](https://github.com/oschwald/maxminddb-rust)
31+
```
32+
city 4,224 ns/iter (+/- 153)
33+
country 2,311 ns/iter (+/- 75)
34+
```
35+
36+
## License
37+
38+
[MIT License](LICENSE).

benches/geoip.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#![feature(test)]
2+
3+
#[cfg(test)]
4+
mod tests {
5+
extern crate test;
6+
use geoip2::{City, Country, Reader};
7+
use std::{net::IpAddr, str::FromStr};
8+
use test::Bencher;
9+
10+
#[bench]
11+
fn bench_country(b: &mut Bencher) {
12+
let buffer = std::fs::read("./testdata/GeoIP2-Country.mmdb").unwrap();
13+
let reader = Reader::<Country>::from_bytes(&buffer).unwrap();
14+
let ip = IpAddr::from_str("81.2.69.142").unwrap();
15+
b.iter(|| {
16+
reader.lookup(ip).unwrap();
17+
});
18+
}
19+
20+
#[bench]
21+
fn bench_city(b: &mut Bencher) {
22+
let buffer = std::fs::read("./testdata/GeoIP2-City.mmdb").unwrap();
23+
let reader = Reader::<City>::from_bytes(&buffer).unwrap();
24+
let ip = IpAddr::from_str("81.2.69.142").unwrap();
25+
b.iter(|| {
26+
reader.lookup(ip).unwrap();
27+
});
28+
}
29+
30+
#[bench]
31+
fn bench_country_oschwald(b: &mut Bencher) {
32+
let reader = maxminddb::Reader::open_readfile("./testdata/GeoIP2-Country.mmdb").unwrap();
33+
let ip = IpAddr::from_str("81.2.69.142").unwrap();
34+
b.iter(|| {
35+
reader.lookup::<maxminddb::geoip2::Country>(ip).unwrap();
36+
});
37+
}
38+
39+
#[bench]
40+
fn bench_city_oschwald(b: &mut Bencher) {
41+
let reader = maxminddb::Reader::open_readfile("./testdata/GeoIP2-City.mmdb").unwrap();
42+
let ip = IpAddr::from_str("81.2.69.142").unwrap();
43+
b.iter(|| {
44+
reader.lookup::<maxminddb::geoip2::City>(ip).unwrap();
45+
});
46+
}
47+
}

codegen/Cargo.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[package]
2+
name = "geoip2-codegen"
3+
version = "0.0.1"
4+
authors = ["IncSW <dev@incsw.in>"]
5+
description = "geoip2 macros"
6+
readme = "README.md"
7+
homepage = "https://github.com/IncSW/geoip2-rs"
8+
documentation = "https://docs.rs/geoip2-codegen"
9+
repository = "https://github.com/IncSW/geoip2-rs"
10+
license = "MIT"
11+
edition = "2018"
12+
13+
[lib]
14+
proc-macro = true
15+
16+
[dependencies]
17+
syn = { version = "1.0.74", features = ["full"] }
18+
quote = "1.0.9"

codegen/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[![crates.io](https://img.shields.io/crates/v/geoip2-codegen?label=latest)](https://crates.io/crates/geoip2-codegen)
2+
[![Documentation](https://docs.rs/geoip2-codegen/badge.svg?version=0.0.1)](https://docs.rs/geoip2-codegen/0.0.1)
3+
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE)
4+
[![Dependency Status](https://deps.rs/crate/geoip2-codegen/0.0.1/status.svg)](https://deps.rs/crate/geoip2-codegen/0.0.1)
5+
![downloads](https://img.shields.io/crates/d/geoip2-codegen.svg)

0 commit comments

Comments
 (0)