wasmer_compiler/
traits.rsuse crate::types::target::CpuFeature;
use crate::Features;
use enumset::EnumSet;
use std::any::Any;
use std::sync::Arc;
use wasmer_types::entity::PrimaryMap;
use wasmer_types::SerializeError;
use wasmer_types::{
DataInitializerLike, MemoryIndex, MemoryStyle, ModuleInfo, TableIndex, TableStyle,
};
pub trait ArtifactCreate<'a>: Send + Sync + Upcastable {
type OwnedDataInitializer: DataInitializerLike<'a> + 'a;
type OwnedDataInitializerIterator: Iterator<Item = Self::OwnedDataInitializer>;
fn create_module_info(&'a self) -> Arc<ModuleInfo>;
fn set_module_info_name(&'a mut self, name: String) -> bool;
fn module_info(&'a self) -> &ModuleInfo;
fn features(&'a self) -> &Features;
fn cpu_features(&'a self) -> EnumSet<CpuFeature>;
fn memory_styles(&'a self) -> &PrimaryMap<MemoryIndex, MemoryStyle>;
fn table_styles(&'a self) -> &PrimaryMap<TableIndex, TableStyle>;
fn data_initializers(&'a self) -> Self::OwnedDataInitializerIterator;
fn serialize(&'a self) -> Result<Vec<u8>, SerializeError>;
}
pub trait Upcastable {
fn upcast_any_ref(&'_ self) -> &'_ dyn Any;
fn upcast_any_mut(&'_ mut self) -> &'_ mut dyn Any;
fn upcast_any_box(self: Box<Self>) -> Box<dyn Any>;
}
impl<T: Any + Send + Sync + 'static> Upcastable for T {
#[inline]
fn upcast_any_ref(&'_ self) -> &'_ dyn Any {
self
}
#[inline]
fn upcast_any_mut(&'_ mut self) -> &'_ mut dyn Any {
self
}
#[inline]
fn upcast_any_box(self: Box<Self>) -> Box<dyn Any> {
self
}
}
impl<'a, O, I>
dyn ArtifactCreate<'a, OwnedDataInitializer = O, OwnedDataInitializerIterator = I> + 'static
{
#[inline]
pub fn downcast_ref<T: 'static>(&'a self) -> Option<&'a T> {
self.upcast_any_ref().downcast_ref::<T>()
}
#[inline]
pub fn downcast_mut<T: 'static>(&'a mut self) -> Option<&'a mut T> {
self.upcast_any_mut().downcast_mut::<T>()
}
}