Skip to main content

relate_engine_api/
engines.rs

1//! Identities a store records so it reopens with the engines that wrote it.
2//! A store written before engines were named reads as the in-memory query
3//! engine and the local write engine.
4
5/// Query engine identity stored in a checkpoint manifest.
6pub const MEMORY_QUERY_ENGINE: &str = "in-memory";
7
8/// Write engine identity stored in a checkpoint manifest.
9pub const LOCAL_WRITE_ENGINE: &str = "local";
10
11#[derive(Debug, Clone, Copy, PartialEq, Eq)]
12pub enum QueryEngineId {
13    InMemory,
14}
15
16impl QueryEngineId {
17    pub fn as_str(self) -> &'static str {
18        match self {
19            Self::InMemory => MEMORY_QUERY_ENGINE,
20        }
21    }
22
23    pub fn parse(raw: &str) -> Option<Self> {
24        match raw {
25            MEMORY_QUERY_ENGINE => Some(Self::InMemory),
26            _ => None,
27        }
28    }
29}
30
31#[derive(Debug, Clone, Copy, PartialEq, Eq)]
32pub enum WriteEngineId {
33    Local,
34}
35
36impl WriteEngineId {
37    pub fn as_str(self) -> &'static str {
38        match self {
39            Self::Local => LOCAL_WRITE_ENGINE,
40        }
41    }
42
43    pub fn parse(raw: &str) -> Option<Self> {
44        match raw {
45            LOCAL_WRITE_ENGINE => Some(Self::Local),
46            _ => None,
47        }
48    }
49}
50
51/// The pair a manifest records. Absent fields mean the historical engines.
52#[derive(Debug, Clone, Copy, PartialEq, Eq)]
53pub struct EngineIds {
54    pub query: QueryEngineId,
55    pub write: WriteEngineId,
56}
57
58impl Default for EngineIds {
59    fn default() -> Self {
60        Self {
61            query: QueryEngineId::InMemory,
62            write: WriteEngineId::Local,
63        }
64    }
65}
66
67impl EngineIds {
68    pub fn parse(query: &str, write: &str) -> Option<Self> {
69        Some(Self {
70            query: QueryEngineId::parse(query)?,
71            write: WriteEngineId::parse(write)?,
72        })
73    }
74}