use crate::{
core::{entities::LayerIds, utils::errors::GraphError},
db::api::view::internal::Base,
prelude::Layer,
};
use enum_dispatch::enum_dispatch;
#[enum_dispatch]
pub trait InternalLayerOps {
fn layer_ids(&self) -> &LayerIds;
fn layer_ids_from_names(&self, key: Layer) -> Result<LayerIds, GraphError>;
fn valid_layer_ids_from_names(&self, key: Layer) -> LayerIds;
}
pub trait InheritLayerOps: Base {}
impl<G: InheritLayerOps> DelegateLayerOps for G
where
G::Base: InternalLayerOps,
{
type Internal = G::Base;
#[inline]
fn graph(&self) -> &Self::Internal {
self.base()
}
}
pub trait DelegateLayerOps {
type Internal: InternalLayerOps + ?Sized;
fn graph(&self) -> &Self::Internal;
}
impl<G: DelegateLayerOps> InternalLayerOps for G {
#[inline]
fn layer_ids(&self) -> &LayerIds {
self.graph().layer_ids()
}
#[inline]
fn layer_ids_from_names(&self, key: Layer) -> Result<LayerIds, GraphError> {
self.graph().layer_ids_from_names(key)
}
#[inline]
fn valid_layer_ids_from_names(&self, key: Layer) -> LayerIds {
self.graph().valid_layer_ids_from_names(key)
}
}