pub struct BuildOptions {
pub profile_codec: Codec,
pub zstd_level: i32,
pub train_zstd_dicts: bool,
pub index_block_size: u32,
pub ipv4_l1_bits: u8,
pub ipv6_l1_bits: u8,
pub row_group_size: u32,
pub struct_dict_row_group_size: u32,
pub dict_block_size: u32,
pub row_order: RowOrderStrategy,
pub prune: Option<PruneConfig>,
}Expand description
Build options for creating .coi files.
Fields§
§profile_codec: CodecCompression profile codec (Codec::Zstd for Compact, Codec::Lz4 for UltraFast, Codec::None for raw).
zstd_level: i32Zstd compression level (1..=19, default 9; ignored for non-Zstd profiles).
train_zstd_dicts: boolWhether to automatically train Section 3: ZstdDicts for IP index blocks (Compact profile).
index_block_size: u32Granule block size for IPv4/IPv6 transition indexes (default 2048 for Compact, 512 for UltraFast).
ipv4_l1_bits: u8L1 direct bucket prefix bits for IPv4 index (default 16).
ipv6_l1_bits: u8L1 direct bucket prefix bits for IPv6 index (default 0; sparse index is ~11 KB in L1 cache).
row_group_size: u32RowGroup size for RecordColumns (default 4096 for Compact, 1024 for UltraFast).
struct_dict_row_group_size: u32RowGroup size for StructDict tables (default 2048 for Compact, 512 for UltraFast).
dict_block_size: u32Block size for large FlatDict tables (> 8192 entries, default 4096).
row_order: RowOrderStrategyRow ordering strategy for unique records.
prune: Option<PruneConfig>Optional build-time field & language pruning (auto-deduplicates records & collapses IP transitions).
Implementations§
Source§impl BuildOptions
impl BuildOptions
Sourcepub fn compact() -> Self
pub fn compact() -> Self
Default Compact profile: Zstd blocks + trained Zstd dictionaries for maximum compression (~4.5–5.5×).
Examples found in repository?
36fn main() -> Result<(), Box<dyn std::error::Error>> {
37 let mut builder = CoipBuilder::new(BuildOptions::compact());
38 builder.set_metadata_field("database_type", serde_json::json!("Custom-Threat-IP"));
39 builder.add_ipv6_alias(AliasRule {
40 prefix: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 0, 0, 0, 0],
41 prefix_len: 96,
42 v4_bit_offset: 96,
43 });
44
45 // Broad corporate /16 overridden by a specific /24 and an explicit deleted /32 hole
46 builder.insert_ipv4_cidr(
47 Ipv4Addr::new(10, 20, 0, 0),
48 16,
49 make_record("Corp-Default", "US", "United States", "美国", 10),
50 )?;
51 builder.insert_ipv4_cidr(
52 Ipv4Addr::new(10, 20, 30, 0),
53 24,
54 make_record("Corp-DMZ", "DE", "Germany", "德国", 85),
55 )?;
56 builder.delete_ipv4_cidr(Ipv4Addr::new(10, 20, 30, 1), 32)?;
57
58 // Native IPv6 /48 + exact /128 host override
59 builder.insert_ipv6_cidr(
60 "2001:db8:abcd::".parse::<Ipv6Addr>()?,
61 48,
62 make_record("IPv6-Pool", "JP", "Japan", "日本", 20),
63 )?;
64 builder.insert_ipv6_cidr(
65 "2001:db8:abcd::99".parse::<Ipv6Addr>()?,
66 128,
67 make_record("IPv6-Honeypot", "JP", "Japan", "日本", 99),
68 )?;
69
70 let (full_bytes, full_stats) = builder.build()?;
71 println!(
72 "Built full .coi: {} bytes ({} unique records, {} IPv4 transitions, {} IPv6 transitions)",
73 full_bytes.len(),
74 full_stats.record_count,
75 full_stats.v4_transitions,
76 full_stats.v6_transitions
77 );
78
79 // Same dataset with build-time pruning (keep only country.iso_code, country.names [en, zh-CN], org)
80 let mut pruned_opts = BuildOptions::ultrafast();
81 pruned_opts.prune = Some(PruneConfig {
82 keep_fields: Some(vec![
83 "org".into(),
84 "country.iso_code".into(),
85 "country.names".into(),
86 ]),
87 languages: Some(BTreeSet::from(["en".into(), "zh-CN".into()])),
88 });
89 let mut builder2 = CoipBuilder::new(pruned_opts);
90 builder2.insert_ipv4_cidr(
91 Ipv4Addr::new(10, 20, 0, 0),
92 16,
93 make_record("Corp-Default", "US", "United States", "美国", 10),
94 )?;
95 let (pruned_bytes, pruned_stats) = builder2.build()?;
96 println!(
97 "Built pruned UltraFast .coi: {} bytes ({} unique records)",
98 pruned_bytes.len(),
99 pruned_stats.record_count
100 );
101
102 Ok(())
103}Sourcepub fn ultrafast() -> Self
pub fn ultrafast() -> Self
UltraFast profile: pure-Rust LZ4 blocks + fine-grained 512/1024 chunks for microsecond cold lookups.
Examples found in repository?
36fn main() -> Result<(), Box<dyn std::error::Error>> {
37 let mut builder = CoipBuilder::new(BuildOptions::compact());
38 builder.set_metadata_field("database_type", serde_json::json!("Custom-Threat-IP"));
39 builder.add_ipv6_alias(AliasRule {
40 prefix: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 0, 0, 0, 0],
41 prefix_len: 96,
42 v4_bit_offset: 96,
43 });
44
45 // Broad corporate /16 overridden by a specific /24 and an explicit deleted /32 hole
46 builder.insert_ipv4_cidr(
47 Ipv4Addr::new(10, 20, 0, 0),
48 16,
49 make_record("Corp-Default", "US", "United States", "美国", 10),
50 )?;
51 builder.insert_ipv4_cidr(
52 Ipv4Addr::new(10, 20, 30, 0),
53 24,
54 make_record("Corp-DMZ", "DE", "Germany", "德国", 85),
55 )?;
56 builder.delete_ipv4_cidr(Ipv4Addr::new(10, 20, 30, 1), 32)?;
57
58 // Native IPv6 /48 + exact /128 host override
59 builder.insert_ipv6_cidr(
60 "2001:db8:abcd::".parse::<Ipv6Addr>()?,
61 48,
62 make_record("IPv6-Pool", "JP", "Japan", "日本", 20),
63 )?;
64 builder.insert_ipv6_cidr(
65 "2001:db8:abcd::99".parse::<Ipv6Addr>()?,
66 128,
67 make_record("IPv6-Honeypot", "JP", "Japan", "日本", 99),
68 )?;
69
70 let (full_bytes, full_stats) = builder.build()?;
71 println!(
72 "Built full .coi: {} bytes ({} unique records, {} IPv4 transitions, {} IPv6 transitions)",
73 full_bytes.len(),
74 full_stats.record_count,
75 full_stats.v4_transitions,
76 full_stats.v6_transitions
77 );
78
79 // Same dataset with build-time pruning (keep only country.iso_code, country.names [en, zh-CN], org)
80 let mut pruned_opts = BuildOptions::ultrafast();
81 pruned_opts.prune = Some(PruneConfig {
82 keep_fields: Some(vec![
83 "org".into(),
84 "country.iso_code".into(),
85 "country.names".into(),
86 ]),
87 languages: Some(BTreeSet::from(["en".into(), "zh-CN".into()])),
88 });
89 let mut builder2 = CoipBuilder::new(pruned_opts);
90 builder2.insert_ipv4_cidr(
91 Ipv4Addr::new(10, 20, 0, 0),
92 16,
93 make_record("Corp-Default", "US", "United States", "美国", 10),
94 )?;
95 let (pruned_bytes, pruned_stats) = builder2.build()?;
96 println!(
97 "Built pruned UltraFast .coi: {} bytes ({} unique records)",
98 pruned_bytes.len(),
99 pruned_stats.record_count
100 );
101
102 Ok(())
103}Trait Implementations§
Source§impl Clone for BuildOptions
impl Clone for BuildOptions
Source§impl Debug for BuildOptions
impl Debug for BuildOptions
Auto Trait Implementations§
impl Forget for BuildOptions
impl Freeze for BuildOptionswhere
*const u8 is !null: Freeze,
PhantomData<String>: Freeze,
*const LeafNode<String, SetValZST> is !null: Freeze,
PhantomData<(Owned, LeafOrInternal)>: Freeze,
PhantomData<Box<(String, SetValZST)>>: Freeze,
impl Move for BuildOptions
impl RefUnwindSafe for BuildOptions
impl Send for BuildOptions
impl Sync for BuildOptions
impl Unpin for BuildOptions
impl UnsafeUnpin for BuildOptionswhere
*const u8 is !null: UnsafeUnpin,
PhantomData<String>: UnsafeUnpin,
*const LeafNode<String, SetValZST> is !null: UnsafeUnpin,
PhantomData<(Owned, LeafOrInternal)>: UnsafeUnpin,
PhantomData<Box<(String, SetValZST)>>: UnsafeUnpin,
impl UnwindSafe for BuildOptions
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more