wasmer_types/
initializers.rsuse crate::indexes::{FunctionIndex, GlobalIndex, MemoryIndex, TableIndex};
use crate::lib::std::boxed::Box;
#[derive(Clone, Debug, Hash, PartialEq, Eq, rkyv::Serialize, rkyv::Deserialize, rkyv::Archive)]
pub struct OwnedTableInitializer {
pub table_index: TableIndex,
pub base: Option<GlobalIndex>,
pub offset: usize,
pub elements: Box<[FunctionIndex]>,
}
#[derive(Clone, Debug, PartialEq, Eq, rkyv::Serialize, rkyv::Deserialize, rkyv::Archive)]
pub struct DataInitializerLocation {
pub memory_index: MemoryIndex,
pub base: Option<GlobalIndex>,
pub offset: usize,
}
#[derive(Debug)]
pub struct DataInitializer<'data> {
pub location: DataInitializerLocation,
pub data: &'data [u8],
}
#[derive(Debug, Clone, PartialEq, Eq, rkyv::Serialize, rkyv::Deserialize, rkyv::Archive)]
pub struct OwnedDataInitializer {
pub location: DataInitializerLocation,
pub data: Vec<u8>,
}
impl OwnedDataInitializer {
pub fn new(borrowed: &DataInitializer<'_>) -> Self {
Self {
location: borrowed.location.clone(),
data: borrowed.data.to_vec(),
}
}
}
impl<'a> From<&'a OwnedDataInitializer> for DataInitializer<'a> {
fn from(init: &'a OwnedDataInitializer) -> Self {
DataInitializer {
location: init.location.clone(),
data: &*init.data,
}
}
}
impl<'a> From<&'a ArchivedOwnedDataInitializer> for DataInitializer<'a> {
fn from(init: &'a ArchivedOwnedDataInitializer) -> Self {
DataInitializer {
location: rkyv::Deserialize::deserialize(&init.location, &mut rkyv::Infallible)
.expect("deserialization cannot fail"),
data: &*init.data,
}
}
}
impl<'a> From<DataInitializer<'a>> for OwnedDataInitializer {
fn from(init: DataInitializer<'a>) -> Self {
OwnedDataInitializer {
location: init.location.clone(),
data: init.data.to_vec(),
}
}
}