use serde::{Serialize, de::DeserializeOwned};
use vantage_core::{Result, error};
use crate::spec::VistaSpec;
use crate::vista::Vista;
pub trait VistaFactory: Send + Sync + 'static {
type TableExtras: Serialize + DeserializeOwned + Default + Send + Sync + 'static;
type ColumnExtras: Serialize + DeserializeOwned + Default + Send + Sync + 'static;
type ReferenceExtras: Serialize + DeserializeOwned + Default + Send + Sync + 'static;
fn build_from_spec(
&self,
spec: VistaSpec<Self::TableExtras, Self::ColumnExtras, Self::ReferenceExtras>,
) -> Result<Vista>;
#[allow(clippy::wrong_self_convention)]
fn from_yaml(&self, yaml: &str) -> Result<Vista> {
let spec: VistaSpec<Self::TableExtras, Self::ColumnExtras, Self::ReferenceExtras> =
serde_yaml_ng::from_str(yaml)
.map_err(|e| error!("Failed to parse VistaSpec YAML", detail = e.to_string()))?;
self.build_from_spec(spec)
}
}