Skip to main content

ferrum_native_ops/
registry.rs

1//! Minimal in-memory native operator registry.
2
3use std::collections::BTreeMap;
4use std::path::PathBuf;
5
6use ferrum_types::NativeOperatorBackend;
7
8#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
9pub struct NativeOperatorKey {
10    pub operator: String,
11    pub backend: NativeOperatorBackend,
12}
13
14impl NativeOperatorKey {
15    pub fn new(operator: impl Into<String>, backend: NativeOperatorBackend) -> Self {
16        Self {
17            operator: operator.into(),
18            backend,
19        }
20    }
21}
22
23#[derive(Debug, Clone, PartialEq, Eq)]
24pub struct NativeOperatorRegistration {
25    pub manifest_path: PathBuf,
26    pub artifact_path: PathBuf,
27}
28
29#[derive(Debug, Default, Clone)]
30pub struct NativeOperatorRegistry {
31    entries: BTreeMap<NativeOperatorKey, NativeOperatorRegistration>,
32}
33
34impl NativeOperatorRegistry {
35    pub fn insert(
36        &mut self,
37        key: NativeOperatorKey,
38        registration: NativeOperatorRegistration,
39    ) -> Option<NativeOperatorRegistration> {
40        self.entries.insert(key, registration)
41    }
42
43    pub fn get(&self, key: &NativeOperatorKey) -> Option<&NativeOperatorRegistration> {
44        self.entries.get(key)
45    }
46
47    pub fn len(&self) -> usize {
48        self.entries.len()
49    }
50
51    pub fn is_empty(&self) -> bool {
52        self.entries.is_empty()
53    }
54}