Skip to main content

nodedb_array/types/
domain.rs

1// SPDX-License-Identifier: Apache-2.0
2
3//! Per-dimension closed interval `[lo, hi]`.
4//!
5//! Stored on each [`crate::schema::DimSpec`]. The interval is closed on
6//! both ends — a coordinate `c` is in-domain iff `lo <= c <= hi`.
7
8use serde::{Deserialize, Serialize};
9
10/// Typed domain bound. Variant tag must match the dim's type.
11#[derive(
12    Debug,
13    Clone,
14    PartialEq,
15    PartialOrd,
16    Serialize,
17    Deserialize,
18    zerompk::ToMessagePack,
19    zerompk::FromMessagePack,
20)]
21pub enum DomainBound {
22    Int64(i64),
23    Float64(f64),
24    TimestampMs(i64),
25    /// String-typed dims use lexicographic ordering on the bound.
26    String(String),
27}
28
29impl Eq for DomainBound {}
30
31/// Closed `[lo, hi]` interval over a single dimension.
32#[derive(
33    Debug,
34    Clone,
35    PartialEq,
36    Eq,
37    Serialize,
38    Deserialize,
39    zerompk::ToMessagePack,
40    zerompk::FromMessagePack,
41)]
42pub struct Domain {
43    pub lo: DomainBound,
44    pub hi: DomainBound,
45}
46
47impl Domain {
48    pub fn new(lo: DomainBound, hi: DomainBound) -> Self {
49        Self { lo, hi }
50    }
51}
52
53#[cfg(test)]
54mod tests {
55    use super::*;
56
57    #[test]
58    fn domain_round_trip_eq() {
59        let d = Domain::new(DomainBound::Int64(0), DomainBound::Int64(1_000_000));
60        let e = d.clone();
61        assert_eq!(d, e);
62    }
63}