mmdb_writer/options.rs
1//! Behavioral option enums for [`Writer`](crate::Writer), modeled as enums rather than bare
2//! booleans so call sites read clearly and future variants stay non-breaking.
3
4/// Whether to install IPv4 aliases in an [`IpVersion::V6`](crate::IpVersion::V6) database.
5///
6/// When enabled (the default), queries arriving in IPv4-mapped (`::ffff:0:0/96`), 6to4
7/// (`2002::/16`), and Teredo (`2001::/32`) form resolve to the same data as the plain IPv4
8/// lookup. This has no effect on IPv4-only databases.
9#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
10#[non_exhaustive]
11pub enum Ipv4Aliasing {
12 /// Install the IPv4 alias subtrees. **Default.**
13 #[default]
14 Enabled,
15 /// Do not install aliases; IPv4-mapped/6to4/Teredo queries will not resolve to IPv4 data.
16 Disabled,
17}
18
19impl Ipv4Aliasing {
20 pub(crate) const fn is_enabled(self) -> bool {
21 matches!(self, Self::Enabled)
22 }
23}
24
25/// Whether reserved (private, documentation, multicast, …) networks are writable.
26///
27/// # Default differs from the Go writer
28///
29/// This crate defaults to [`ReservedNetworks::Included`] — inserts into reserved space are
30/// allowed — whereas the Go `mmdbwriter` excludes them by default. The permissive default is
31/// deliberate: documentation ranges such as `192.0.2.0/24` and `2001:db8::/32` are reserved,
32/// and rejecting them would make the most common example and test networks fail. Choose
33/// [`ReservedNetworks::Excluded`] to match the Go behavior.
34#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
35#[non_exhaustive]
36pub enum ReservedNetworks {
37 /// Allow inserting into reserved networks. **Default** (differs from the Go writer).
38 #[default]
39 Included,
40 /// Reject inserts that target reserved space (returning [`Error::ReservedNetwork`]) and
41 /// carve reserved networks out of any broader insert that covers them.
42 ///
43 /// [`Error::ReservedNetwork`]: crate::Error::ReservedNetwork
44 Excluded,
45}
46
47impl ReservedNetworks {
48 pub(crate) const fn is_excluded(self) -> bool {
49 matches!(self, Self::Excluded)
50 }
51}
52
53/// Whether the metadata section may use data-section pointers.
54///
55/// Pointers make the metadata marginally smaller by sharing repeated strings, but a few
56/// historic readers mishandle them. Disable to emit fully inline metadata.
57#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
58#[non_exhaustive]
59pub enum MetadataPointers {
60 /// Allow pointers in the metadata section. **Default.**
61 #[default]
62 Enabled,
63 /// Emit metadata without any pointers.
64 Disabled,
65}
66
67impl MetadataPointers {
68 pub(crate) const fn is_disabled(self) -> bool {
69 matches!(self, Self::Disabled)
70 }
71}
72
73/// How [`Writer::insert_merged`](crate::Writer::insert_merged) combines a new value with the
74/// value already covering a network.
75#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
76#[non_exhaustive]
77pub enum MergeStrategy {
78 /// Replace the existing value entirely (identical to
79 /// [`insert`](crate::Writer::insert)). **Default.**
80 #[default]
81 Replace,
82 /// Merge the top level of two maps: the union of keys, with the new value winning on
83 /// conflicts. See [`Value::merge_top_level`](crate::Value::merge_top_level).
84 TopLevelMerge,
85 /// Recursively merge nested maps and concatenate arrays. See
86 /// [`Value::merge_deep`](crate::Value::merge_deep).
87 DeepMerge,
88}