2024-02-19 14:10:08 +01:00
|
|
|
use crate::executor::{javascript::NodeJSExecutor, php::PhpExecutor, python::PythonExecutor};
|
2024-02-18 06:16:55 +01:00
|
|
|
|
2024-02-19 14:10:08 +01:00
|
|
|
pub mod javascript;
|
2024-02-19 07:34:45 +01:00
|
|
|
pub mod php;
|
2024-02-18 06:16:55 +01:00
|
|
|
pub mod python;
|
2024-02-19 07:34:45 +01:00
|
|
|
|
2024-02-18 06:16:55 +01:00
|
|
|
pub mod helper;
|
|
|
|
|
|
|
|
pub fn executors() -> Vec<Box<dyn Executor>> {
|
|
|
|
vec![
|
2024-02-19 14:10:08 +01:00
|
|
|
Box::new(NodeJSExecutor {}),
|
2024-02-19 07:34:45 +01:00
|
|
|
Box::new(PhpExecutor {}),
|
2024-02-18 06:16:55 +01:00
|
|
|
Box::new(PythonExecutor {}),
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn executors_id() -> Vec<String> {
|
2024-03-03 17:55:27 +01:00
|
|
|
filter_unavailable(&executors())
|
2024-02-18 06:16:55 +01:00
|
|
|
.iter()
|
|
|
|
.map(|x| x.id())
|
|
|
|
.collect()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_executor<'a, T: Into<String>>(id: T, executors: &'a Vec<Box<dyn Executor>>) -> Option<&'a Box<dyn Executor>> {
|
|
|
|
let id: String = id.into();
|
|
|
|
let found = executors.iter().find(|x| x.id() == id);
|
|
|
|
found
|
|
|
|
}
|
|
|
|
|
2024-03-03 17:55:27 +01:00
|
|
|
pub fn filter_unavailable<'a>(executors: &'a Vec<Box<dyn Executor>>) -> Vec<&Box<dyn Executor>> {
|
|
|
|
executors
|
|
|
|
.iter()
|
|
|
|
.filter(|x| x.available())
|
|
|
|
.collect()
|
|
|
|
}
|
|
|
|
|
2024-02-18 06:16:55 +01:00
|
|
|
pub trait Executor {
|
|
|
|
fn id(&self) -> String;
|
|
|
|
fn exec(&self, code: String) -> Result<String, String>;
|
2024-03-03 17:55:27 +01:00
|
|
|
fn available(&self) -> bool;
|
2024-02-18 06:16:55 +01:00
|
|
|
}
|