Skip to main content

oxibrain_index/
spec.rs

1//! Shared specification types used by both the core query layer and the index
2//! algorithm layer. Lives in `oxibrain-index` (the lower crate per §18 rule 1)
3//! so that `oxibrain-core` can depend on `oxibrain-index` without a cycle.
4
5use serde::{Deserialize, Serialize};
6
7/// Edge direction for graph traversal.
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9#[serde(rename_all = "snake_case")]
10pub enum Direction {
11    Out,
12    In,
13    Both,
14}
15
16/// Predicate filter for graph traversal.
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(rename_all = "snake_case")]
19pub enum PredicateFilter {
20    AllowAll,
21    Allow(Vec<String>),
22    Deny(Vec<String>),
23}
24
25impl PredicateFilter {
26    pub fn allows(&self, predicate: &str) -> bool {
27        match self {
28            PredicateFilter::AllowAll => true,
29            PredicateFilter::Allow(list) => list.iter().any(|p| p == predicate),
30            PredicateFilter::Deny(list) => !list.iter().any(|p| p == predicate),
31        }
32    }
33}