Skip to main content

laminar_core/lookup/
table.rs

1//! Lookup result type.
2
3use arrow_array::RecordBatch;
4
5/// Result of a lookup operation.
6#[derive(Debug, Clone)]
7pub enum LookupResult {
8    /// Cache hit.
9    Hit(RecordBatch),
10    /// Async lookup in progress.
11    Pending,
12    /// Key not found.
13    NotFound,
14}
15
16impl LookupResult {
17    /// Returns `true` if this is a cache hit.
18    #[must_use]
19    pub const fn is_hit(&self) -> bool {
20        matches!(self, Self::Hit(_))
21    }
22
23    /// Returns `true` if the key was not found.
24    #[must_use]
25    pub const fn is_not_found(&self) -> bool {
26        matches!(self, Self::NotFound)
27    }
28
29    /// Extracts the `RecordBatch` from a `Hit`.
30    #[must_use]
31    pub fn into_batch(self) -> Option<RecordBatch> {
32        match self {
33            Self::Hit(b) => Some(b),
34            _ => None,
35        }
36    }
37}
38
39impl PartialEq for LookupResult {
40    fn eq(&self, other: &Self) -> bool {
41        match (self, other) {
42            (Self::Hit(a), Self::Hit(b)) => a == b,
43            (Self::Pending, Self::Pending) | (Self::NotFound, Self::NotFound) => true,
44            _ => false,
45        }
46    }
47}
48
49impl Eq for LookupResult {}