Skip to content

Commit c068671

Browse files
committed
Fix introspection
1 parent 57e5019 commit c068671

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/ast/mod.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::any::Any;
1+
use std::any::{Any, TypeId};
22
use std::borrow::Cow;
33
use std::path::PathBuf;
44
use std::pin::Pin;
@@ -243,7 +243,7 @@ pub struct Arg {
243243

244244
pub struct Pipe {
245245
_context: Arc<Context>,
246-
modules: HashMap<String, Arc<dyn CommandRunner + Send + Sync>>,
246+
modules: IndexMap<String, Arc<dyn CommandRunner + Send + Sync>>,
247247
pub(crate) defn: Arc<PipelineDefinition>,
248248
}
249249

@@ -318,7 +318,7 @@ impl PipelineHandle {
318318
impl Pipe {
319319
#[inline]
320320
pub fn new(context: Arc<Context>, defn: Arc<PipelineDefinition>) -> Result<Self, Error> {
321-
let mut cache: HashMap<String, Arc<dyn CommandRunner + Send + Sync>> = HashMap::new();
321+
let mut cache: IndexMap<String, Arc<dyn CommandRunner + Send + Sync>> = IndexMap::new();
322322

323323
for (key, command) in defn.commands.iter() {
324324
if cache.contains_key(&**key) {
@@ -352,11 +352,14 @@ impl Pipe {
352352
})
353353
}
354354

355-
pub fn command<T: CommandRunner>(&self, key: &str) -> Option<&Arc<T>> {
355+
pub fn command<T: CommandRunner>(&self, key: &str) -> Option<&T> {
356356
self.modules
357357
.get(key)
358-
.map(|x| x as &dyn Any)
359-
.and_then(|x| x.downcast_ref::<Arc<T>>())
358+
.map(|x| &**x as &(dyn Any + Send + Sync))
359+
.and_then(|x| {
360+
println!("Command TypeId: {:?}", x.type_id());
361+
x.downcast_ref::<T>()
362+
})
360363
}
361364

362365
pub async fn create_stream(

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ impl Bundle {
211211
&self.pipe.defn
212212
}
213213

214-
pub fn command<T: modules::CommandRunner>(&self, key: &str) -> Option<&Arc<T>> {
214+
pub fn command<T: modules::CommandRunner>(&self, key: &str) -> Option<&T> {
215215
self.pipe.command(key)
216216
}
217217
}

0 commit comments

Comments
 (0)