datalog_structural_model/
capability.rs1use crate::{Aggregator, BindingKind, FilterKind};
3use std::collections::BTreeSet;
4
5#[derive(
8 Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize,
9)]
10pub enum DatalogFeature {
11 StratifiedNegation,
13 TripleTerms,
15 SkolemGeneration,
17 Filter(FilterKind),
19 Binding(BindingKind),
21 Aggregate(Aggregator),
23}
24
25#[derive(Clone, Debug, Default, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
27#[serde(transparent)]
28pub struct DatalogCapabilities(BTreeSet<DatalogFeature>);
29impl DatalogCapabilities {
30 #[must_use]
32 pub fn positive() -> Self {
33 Self::default()
34 }
35 #[must_use]
37 pub fn with(mut self, feature: DatalogFeature) -> Self {
38 self.0.insert(feature);
39 self
40 }
41 #[must_use]
43 pub fn contains(&self, feature: &DatalogFeature) -> bool {
44 self.0.contains(feature)
45 }
46 pub fn iter(&self) -> impl Iterator<Item = &DatalogFeature> {
48 self.0.iter()
49 }
50 #[must_use]
52 pub fn all_model_features() -> Self {
53 let mut result = Self::positive()
54 .with(DatalogFeature::StratifiedNegation)
55 .with(DatalogFeature::TripleTerms)
56 .with(DatalogFeature::SkolemGeneration);
57 for kind in FilterKind::ALL {
58 result.0.insert(DatalogFeature::Filter(*kind));
59 }
60 for kind in BindingKind::ALL {
61 result.0.insert(DatalogFeature::Binding(*kind));
62 }
63 for kind in [
64 Aggregator::Count,
65 Aggregator::Sum,
66 Aggregator::Min,
67 Aggregator::Max,
68 Aggregator::Avg,
69 ] {
70 result.0.insert(DatalogFeature::Aggregate(kind));
71 }
72 result
73 }
74 pub(crate) fn insert(&mut self, feature: DatalogFeature) {
75 self.0.insert(feature);
76 }
77 pub(crate) fn missing_from(&self, supported: &Self) -> Self {
78 Self(self.0.difference(&supported.0).copied().collect())
79 }
80 pub(crate) fn is_empty(&self) -> bool {
81 self.0.is_empty()
82 }
83}