traverse_runtime/executor/
mod.rs1pub mod native;
12#[cfg(feature = "native-executors")]
13pub mod thread_pool;
14#[cfg(feature = "wasmtime-executor")]
15pub mod wasm;
16
17pub use native::NativeExecutor;
18#[cfg(feature = "native-executors")]
19pub use thread_pool::{ConfigError, ThreadPoolExecutor, ThreadPoolExecutorConfig};
20#[cfg(feature = "wasmtime-executor")]
21pub use wasm::{
22 HostAbiImport, HostAbiValidation, SUPPORTED_HOST_ABI_VERSION, WasmExecutionLimits,
23 WasmExecutor, WasmModuleCacheConfig, WasmModuleCacheStats, supported_host_abi_versions,
24 verify_wasm_host_abi_bytes,
25};
26
27use serde_json::Value;
28
29#[derive(Debug, Clone, PartialEq, Eq, Hash)]
31pub enum ArtifactType {
32 Native,
34 Wasm,
36}
37
38#[derive(Debug, Clone)]
40pub struct ExecutorCapability {
41 pub capability_id: String,
43 pub artifact_type: ArtifactType,
45 pub wasm_binary_path: Option<String>,
47 pub wasm_checksum: Option<String>,
49 pub host_abi_version: Option<String>,
51}
52
53#[derive(Debug, Clone, PartialEq, Eq)]
55pub enum ExecutorError {
56 BinaryLoadFailed(String),
58 ChecksumMismatch { expected: String, actual: String },
60 RuntimeSetupFailed(String),
62 MalformedWasmArtifact { error_code: String, detail: String },
64 UnsupportedAbiVersion {
66 error_code: String,
67 requested: String,
68 supported: String,
69 },
70 UnauthorizedHostImport {
72 error_code: String,
73 abi_version: String,
74 module: String,
75 name: String,
76 },
77 ExecutionFailed(String),
79 Timeout(String),
81 ResourceExhausted(String),
83 OutputDeserializationFailed(String),
85 UnsupportedArtifactType,
87}
88
89impl std::fmt::Display for ExecutorError {
90 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
91 match self {
92 Self::BinaryLoadFailed(msg) => write!(f, "binary load failed: {msg}"),
93 Self::ChecksumMismatch { expected, actual } => {
94 write!(f, "checksum mismatch: expected {expected}, got {actual}")
95 }
96 Self::RuntimeSetupFailed(msg) => write!(f, "runtime setup failed: {msg}"),
97 Self::MalformedWasmArtifact { error_code, detail } => {
98 write!(f, "{error_code}: {detail}")
99 }
100 Self::UnsupportedAbiVersion {
101 error_code,
102 requested,
103 supported,
104 } => write!(
105 f,
106 "{error_code}: requested Traverse Host ABI {requested}, supported {supported}"
107 ),
108 Self::UnauthorizedHostImport {
109 error_code,
110 abi_version,
111 module,
112 name,
113 } => write!(
114 f,
115 "{error_code}: ABI {abi_version} does not allow import {module}::{name}"
116 ),
117 Self::ExecutionFailed(msg) => write!(f, "execution failed: {msg}"),
118 Self::Timeout(msg) => write!(f, "execution timed out: {msg}"),
119 Self::ResourceExhausted(msg) => write!(f, "resource exhausted: {msg}"),
120 Self::OutputDeserializationFailed(msg) => {
121 write!(f, "output deserialization failed: {msg}")
122 }
123 Self::UnsupportedArtifactType => {
124 write!(f, "unsupported artifact type for this executor")
125 }
126 }
127 }
128}
129
130impl std::error::Error for ExecutorError {}
131
132pub trait CapabilityExecutor: Send + Sync {
136 fn execute(
142 &self,
143 capability: &ExecutorCapability,
144 input: &Value,
145 ) -> Result<Value, ExecutorError>;
146}