use crate::ast::TypedStreamSpec;
pub trait SpecProvider {
fn spec_name(&self) -> &str;
fn entity_name(&self) -> &str;
fn get_spec(&self) -> Box<dyn std::any::Any>;
fn description(&self) -> Option<&str> {
None
}
}
pub struct ErasedStreamSpec {
pub spec_name: String,
pub entity_name: String,
pub description: Option<String>,
spec_any: Box<dyn std::any::Any>,
}
impl ErasedStreamSpec {
pub fn new<S: 'static>(
spec_name: String,
entity_name: String,
spec: TypedStreamSpec<S>,
description: Option<String>,
) -> Self {
ErasedStreamSpec {
spec_name,
entity_name,
description,
spec_any: Box::new(spec),
}
}
pub fn downcast<S: 'static>(&self) -> Option<&TypedStreamSpec<S>> {
self.spec_any.downcast_ref::<TypedStreamSpec<S>>()
}
}