Skip to main content

BuildOptions

Struct BuildOptions 

Source
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: Codec

Compression profile codec (Codec::Zstd for Compact, Codec::Lz4 for UltraFast, Codec::None for raw).

§zstd_level: i32

Zstd compression level (1..=19, default 9; ignored for non-Zstd profiles).

§train_zstd_dicts: bool

Whether to automatically train Section 3: ZstdDicts for IP index blocks (Compact profile).

§index_block_size: u32

Granule block size for IPv4/IPv6 transition indexes (default 2048 for Compact, 512 for UltraFast).

§ipv4_l1_bits: u8

L1 direct bucket prefix bits for IPv4 index (default 16).

§ipv6_l1_bits: u8

L1 direct bucket prefix bits for IPv6 index (default 0; sparse index is ~11 KB in L1 cache).

§row_group_size: u32

RowGroup size for RecordColumns (default 4096 for Compact, 1024 for UltraFast).

§struct_dict_row_group_size: u32

RowGroup size for StructDict tables (default 2048 for Compact, 512 for UltraFast).

§dict_block_size: u32

Block size for large FlatDict tables (> 8192 entries, default 4096).

§row_order: RowOrderStrategy

Row ordering strategy for unique records.

§prune: Option<PruneConfig>

Optional build-time field pruning (auto-deduplicates records & collapses IP transitions).

Implementations§

Source§

impl BuildOptions

Source

pub fn compact() -> Self

Default Compact profile: Zstd blocks + trained Zstd dictionaries for maximum compression (~4.5–5.5×).

Examples found in repository?
examples/custom_db.rs (line 26)
25fn main() -> Result<(), Box<dyn std::error::Error>> {
26    let mut builder = CoipBuilder::new(BuildOptions::compact());
27    builder.set_metadata_field("database_type", serde_json::json!("Custom-Threat-IP"));
28    builder.add_ipv6_alias(AliasRule {
29        prefix: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 0, 0, 0, 0],
30        prefix_len: 96,
31        v4_bit_offset: 96,
32    });
33
34    // Broad corporate /16 overridden by a specific /24 and an explicit deleted /32 hole
35    builder.insert_ipv4_cidr(
36        Ipv4Addr::new(10, 20, 0, 0),
37        16,
38        make_record("Corp-Default", "US", "United States", 10),
39    )?;
40    builder.insert_ipv4_cidr(
41        Ipv4Addr::new(10, 20, 30, 0),
42        24,
43        make_record("Corp-DMZ", "DE", "Germany", 85),
44    )?;
45    builder.delete_ipv4_cidr(Ipv4Addr::new(10, 20, 30, 1), 32)?;
46
47    // Native IPv6 /48 + exact /128 host override
48    builder.insert_ipv6_cidr(
49        "2001:db8:abcd::".parse::<Ipv6Addr>()?,
50        48,
51        make_record("IPv6-Pool", "JP", "Japan", 20),
52    )?;
53    builder.insert_ipv6_cidr(
54        "2001:db8:abcd::99".parse::<Ipv6Addr>()?,
55        128,
56        make_record("IPv6-Honeypot", "JP", "Japan", 99),
57    )?;
58
59    let (full_bytes, full_stats) = builder.build()?;
60    println!(
61        "Built full .coi: {} bytes ({} unique records, {} IPv4 transitions, {} IPv6 transitions)",
62        full_bytes.len(),
63        full_stats.record_count,
64        full_stats.v4_transitions,
65        full_stats.v6_transitions
66    );
67
68    // Same dataset with build-time field pruning (keep only country.iso_code, country.name, org)
69    let mut pruned_opts = BuildOptions::ultrafast();
70    pruned_opts.prune = Some(PruneConfig {
71        keep_fields: Some(vec![
72            "org".into(),
73            "country.iso_code".into(),
74            "country.name".into(),
75        ]),
76    });
77    let mut builder2 = CoipBuilder::new(pruned_opts);
78    builder2.insert_ipv4_cidr(
79        Ipv4Addr::new(10, 20, 0, 0),
80        16,
81        make_record("Corp-Default", "US", "United States", 10),
82    )?;
83    let (pruned_bytes, pruned_stats) = builder2.build()?;
84    println!(
85        "Built pruned UltraFast .coi: {} bytes ({} unique records)",
86        pruned_bytes.len(),
87        pruned_stats.record_count
88    );
89
90    Ok(())
91}
Source

pub fn ultrafast() -> Self

UltraFast profile: pure-Rust LZ4 blocks + fine-grained 512/1024 chunks for microsecond cold lookups.

Examples found in repository?
examples/custom_db.rs (line 69)
25fn main() -> Result<(), Box<dyn std::error::Error>> {
26    let mut builder = CoipBuilder::new(BuildOptions::compact());
27    builder.set_metadata_field("database_type", serde_json::json!("Custom-Threat-IP"));
28    builder.add_ipv6_alias(AliasRule {
29        prefix: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 0, 0, 0, 0],
30        prefix_len: 96,
31        v4_bit_offset: 96,
32    });
33
34    // Broad corporate /16 overridden by a specific /24 and an explicit deleted /32 hole
35    builder.insert_ipv4_cidr(
36        Ipv4Addr::new(10, 20, 0, 0),
37        16,
38        make_record("Corp-Default", "US", "United States", 10),
39    )?;
40    builder.insert_ipv4_cidr(
41        Ipv4Addr::new(10, 20, 30, 0),
42        24,
43        make_record("Corp-DMZ", "DE", "Germany", 85),
44    )?;
45    builder.delete_ipv4_cidr(Ipv4Addr::new(10, 20, 30, 1), 32)?;
46
47    // Native IPv6 /48 + exact /128 host override
48    builder.insert_ipv6_cidr(
49        "2001:db8:abcd::".parse::<Ipv6Addr>()?,
50        48,
51        make_record("IPv6-Pool", "JP", "Japan", 20),
52    )?;
53    builder.insert_ipv6_cidr(
54        "2001:db8:abcd::99".parse::<Ipv6Addr>()?,
55        128,
56        make_record("IPv6-Honeypot", "JP", "Japan", 99),
57    )?;
58
59    let (full_bytes, full_stats) = builder.build()?;
60    println!(
61        "Built full .coi: {} bytes ({} unique records, {} IPv4 transitions, {} IPv6 transitions)",
62        full_bytes.len(),
63        full_stats.record_count,
64        full_stats.v4_transitions,
65        full_stats.v6_transitions
66    );
67
68    // Same dataset with build-time field pruning (keep only country.iso_code, country.name, org)
69    let mut pruned_opts = BuildOptions::ultrafast();
70    pruned_opts.prune = Some(PruneConfig {
71        keep_fields: Some(vec![
72            "org".into(),
73            "country.iso_code".into(),
74            "country.name".into(),
75        ]),
76    });
77    let mut builder2 = CoipBuilder::new(pruned_opts);
78    builder2.insert_ipv4_cidr(
79        Ipv4Addr::new(10, 20, 0, 0),
80        16,
81        make_record("Corp-Default", "US", "United States", 10),
82    )?;
83    let (pruned_bytes, pruned_stats) = builder2.build()?;
84    println!(
85        "Built pruned UltraFast .coi: {} bytes ({} unique records)",
86        pruned_bytes.len(),
87        pruned_stats.record_count
88    );
89
90    Ok(())
91}

Trait Implementations§

Source§

impl Clone for BuildOptions

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BuildOptions

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for BuildOptions

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Forget for BuildOptions

§

impl Freeze for BuildOptions

§

impl Move for BuildOptions

§

impl RefUnwindSafe for BuildOptions

§

impl Send for BuildOptions
where RawVecInner: Send,

§

impl Sync for BuildOptions
where RawVecInner: Sync,

§

impl Unpin for BuildOptions
where *const u8 is !null: Unpin,

§

impl UnsafeUnpin for BuildOptions

§

impl UnwindSafe for BuildOptions
where RawVecInner: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.