hyperion/effects/
providers.rs1use std::{path::Path, sync::Arc};
2
3use thiserror::Error;
4
5use super::instance::RuntimeMethods;
6
7#[cfg(feature = "python")]
8mod python;
9
10#[derive(Debug, Error)]
11pub enum ProviderError {
12 #[cfg(feature = "python")]
13 #[error(transparent)]
14 Python(#[from] python::Error),
15}
16
17pub trait Provider: std::fmt::Debug + Send + Sync {
21 fn supports(&self, script_path: &str) -> bool;
32
33 fn run(
41 &self,
42 full_script_path: &Path,
43 args: serde_json::Value,
44 methods: Arc<dyn RuntimeMethods>,
45 ) -> Result<(), ProviderError>;
46}
47
48#[derive(Debug)]
49pub struct Providers {
50 providers: Vec<Arc<dyn Provider>>,
51}
52
53impl Default for Providers {
54 fn default() -> Self {
55 Self::new()
56 }
57}
58
59impl Providers {
60 pub fn new() -> Self {
61 Self {
62 providers: vec![
63 #[cfg(feature = "python")]
64 Arc::new(python::PythonProvider::new()),
65 ],
66 }
67 }
68
69 pub fn get(&self, script_path: &str) -> Option<Arc<dyn Provider>> {
70 self.providers
71 .iter()
72 .find(|provider| provider.supports(script_path))
73 .cloned()
74 }
75}