hyperstack_interpreter/
spec_trait.rs1use crate::ast::TypedStreamSpec;
2
3pub trait SpecProvider {
8 fn spec_name(&self) -> &str;
10
11 fn entity_name(&self) -> &str;
13
14 fn get_spec(&self) -> Box<dyn std::any::Any>;
16
17 fn description(&self) -> Option<&str> {
19 None
20 }
21}
22
23pub struct ErasedStreamSpec {
27 pub spec_name: String,
28 pub entity_name: String,
29 pub description: Option<String>,
30 spec_any: Box<dyn std::any::Any>,
32}
33
34impl ErasedStreamSpec {
35 pub fn new<S: 'static>(
36 spec_name: String,
37 entity_name: String,
38 spec: TypedStreamSpec<S>,
39 description: Option<String>,
40 ) -> Self {
41 ErasedStreamSpec {
42 spec_name,
43 entity_name,
44 description,
45 spec_any: Box::new(spec),
46 }
47 }
48
49 pub fn downcast<S: 'static>(&self) -> Option<&TypedStreamSpec<S>> {
51 self.spec_any.downcast_ref::<TypedStreamSpec<S>>()
52 }
53}
54