use crate::Engine;
use enumset::EnumSet;
use wasmer_compiler::{CompileError, CpuFeature, Features};
use wasmer_types::FunctionIndex;
use wasmer_vm::Artifact;
mod private {
pub struct Internal(pub(super) ());
}
pub trait Executable {
fn load(
&self,
engine: &(dyn Engine + 'static),
) -> Result<std::sync::Arc<dyn Artifact>, CompileError>;
fn features(&self) -> Features;
fn cpu_features(&self) -> EnumSet<CpuFeature>;
fn serialize(&self) -> Result<Vec<u8>, Box<dyn std::error::Error + Send + Sync>>;
fn function_name(&self, index: FunctionIndex) -> Option<&str>;
#[doc(hidden)]
fn type_id(&self, _: private::Internal) -> std::any::TypeId
where
Self: 'static,
{
std::any::TypeId::of::<Self>()
}
}
impl dyn Executable {
pub fn downcast_ref<T: Executable + 'static>(&self) -> Option<&T> {
if std::any::TypeId::of::<T>() == self.type_id(private::Internal(())) {
unsafe { Some(&*(self as *const dyn Executable as *const T)) }
} else {
None
}
}
}