fix: support arbitrary types in task dependencies
Enable tasks to accept ANY type implementing Clone + Send + Sync as dependencies, without requiring users to implement ExtractInput trait. The #[task] macro now generates task-specific extraction logic inline via a new extract_and_run() method. This leverages the macro's perfect compile-time knowledge of parameter types to handle extraction for: - Zero parameters (unit type, source tasks) - Single parameter (any Clone + Send + Sync type) - Multiple parameters (tuples, awaited concurrently) Previously, only hardcoded primitive types and specific stdlib types worked. Custom user types required manual ExtractInput implementations. Now custom types work automatically with zero API changes. Changes: - Add extract_and_run() method to Task trait (internal/hidden) - Generate inline extraction in #[task] macro based on parameter count - Remove ExtractInput bound from DagRunner::add_task() - Retain ExtractInput for internal task_fn() test helper - Add comprehensive custom type tests No breaking changes - purely internal implementation improvement.
This commit is contained in:
7 files changed
+300
-14
No files matched your search
@@ -83,6 +83,17 @@ impl Task for CustomTask {
|
||||
self.state
|
||||
})
|
||||
}
|
||||
|
||||
#[allow(refining_impl_trait)]
|
||||
fn extract_and_run(
|
||||
self,
|
||||
_receivers: Vec<Box<dyn std::any::Any + Send>>,
|
||||
) -> Pin<Box<dyn Future<Output = Result<Self::Output, String>> + Send>> {
|
||||
Box::pin(async move {
|
||||
// This is a test helper - just return an error
|
||||
Err("extract_and_run not implemented for CustomTask (test helper)".to_string())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
||||
Reference in new issue
Block a user