:globe_with_meridians: [中文简体](README_zh.md) | [English](README.md)

# ip2region xdb rust generation implementation

## Program Compilation

```bash
$ cd maker/rust/maker
$ cargo build -r
```

After successful compilation, the executable file is located at `./target/release/maker`

## `xdb` Data Generation

```bash
# CWD ip2region/maker/rust/maker
$ ./target/release/maker --help
Usage: maker [OPTIONS] --src <SRC> --dst <DST> --ip-version <IP_VERSION>

Options:
      --src <SRC>
          ip source region txt filepath

      --dst <DST>
          generated xdb filepath

      --ip-version <IP_VERSION>
          Possible values:
          - v4: IPv4
          - v6: Ipv6

      --index-policy <INDEX_POLICY>
          index cache policy

          [default: vector-index]
          [possible values: vector-index, b-tree-index]

      --filter-fields <FILTER_FIELDS>
          region filter fields, the index of the fields, e.g. `1,2,3,5`

  -h, --help
          Print help (see a summary with '-h')
```

For example, use the default raw data under the repository's data/ directory to generate the xdb file to the current directory (`ip2region/maker/rust/maker`):

```bash
# ipv6
./target/release/maker --src=../../../data/ipv6_source.txt --dst=./target/ipv6.xdb --ip-version v6
# ipv4
./target/release/maker --src=../../../data/ipv4_source.txt --dst=./target/ipv4.xdb --ip-version v4
```

## `xdb` Data Search and bench Test

For search functions and testing based on the xdb format, see [ip2region bindings](../../binding)

## Comparison with xdb files generated by other makers

It is recommended to use `vbindiff`. The only difference from other files should be the create time information; all other data must be identical.

Build xdb using the golang version maker

```bash
$ cd maker golang
$ make
$ ./xdb_maker gen --src=../../data/ipv4_source.txt --dst=./ip2region_v4.xdb --version=ipv4
$ ./xdb_maker gen --src=../../data/ipv6_source.txt --dst=./ip2region_v6.xdb --version=ipv6
```

Compare xdb differences

```bash
$ cd maker/rust/maker
# Generate xdb files using rust maker
$ ./target/release/maker --src=../../../data/ipv4_source.txt --dst=./target/ipv4.xdb --ip-version v4
$ ./target/release/maker --src=../../../data/ipv6_source.txt --dst=./target/ipv6.xdb --ip-version v6
# Compare with golang generated files
$ vbindiff ./ipv4.xdb ../../golang/ip2region_v4.xdb
$ vbindiff ./ipv6.xdb ../../golang/ip2region_v6.xdb
```
