wasmer_engine/
executable.rs1use crate::Engine;
2use enumset::EnumSet;
3use wasmer_compiler::{CompileError, CpuFeature, Features};
4use wasmer_types::FunctionIndex;
5use wasmer_vm::Artifact;
6
7mod private {
8 pub struct Internal(pub(super) ());
9}
10
11pub trait Executable {
16 fn load(
20 &self,
21 engine: &(dyn Engine + 'static),
22 ) -> Result<std::sync::Arc<dyn Artifact>, CompileError>;
23
24 fn features(&self) -> Features;
26
27 fn cpu_features(&self) -> EnumSet<CpuFeature>;
29
30 fn serialize(&self) -> Result<Vec<u8>, Box<dyn std::error::Error + Send + Sync>>;
32
33 fn function_name(&self, index: FunctionIndex) -> Option<&str>;
37
38 #[doc(hidden)]
40 fn type_id(&self, _: private::Internal) -> std::any::TypeId
41 where
42 Self: 'static,
43 {
44 std::any::TypeId::of::<Self>()
45 }
46}
47
48impl dyn Executable {
49 pub fn downcast_ref<T: Executable + 'static>(&self) -> Option<&T> {
51 if std::any::TypeId::of::<T>() == self.type_id(private::Internal(())) {
52 unsafe { Some(&*(self as *const dyn Executable as *const T)) }
53 } else {
54 None
55 }
56 }
57}