use crate::db::access::execution_contract::ExecutionPathPayload;
#[derive(Clone, Debug, Eq, PartialEq)]
pub(in crate::db) enum ExecutableAccessNode<'a, K> {
Path(ExecutionPathPayload<'a, K>),
Union(Vec<ExecutableAccessPlan<'a, K>>),
Intersection(Vec<ExecutableAccessPlan<'a, K>>),
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub(in crate::db) struct ExecutableAccessPlan<'a, K> {
node: ExecutableAccessNode<'a, K>,
}
impl<'a, K> ExecutableAccessPlan<'a, K> {
#[must_use]
pub(in crate::db) const fn for_path(path: ExecutionPathPayload<'a, K>) -> Self {
Self {
node: ExecutableAccessNode::Path(path),
}
}
#[must_use]
pub(in crate::db) const fn union(children: Vec<Self>) -> Self {
Self {
node: ExecutableAccessNode::Union(children),
}
}
#[must_use]
pub(in crate::db) const fn intersection(children: Vec<Self>) -> Self {
Self {
node: ExecutableAccessNode::Intersection(children),
}
}
#[must_use]
pub(in crate::db) const fn node(&self) -> &ExecutableAccessNode<'a, K> {
&self.node
}
#[must_use]
pub(in crate::db) const fn as_path(&self) -> Option<&ExecutionPathPayload<'a, K>> {
match &self.node {
ExecutableAccessNode::Path(path) => Some(path),
ExecutableAccessNode::Union(_) | ExecutableAccessNode::Intersection(_) => None,
}
}
}