wasmer_runtime_core_fl/structures/
boxed.rs

1use super::{SliceMap, TypedIndex};
2use std::{
3    marker::PhantomData,
4    mem,
5    ops::{Deref, DerefMut},
6};
7
8/// Boxed map.
9#[derive(Debug, Clone)]
10pub struct BoxedMap<K, V>
11where
12    K: TypedIndex,
13{
14    elems: Box<[V]>,
15    _marker: PhantomData<K>,
16}
17
18impl<K, V> BoxedMap<K, V>
19where
20    K: TypedIndex,
21{
22    pub(in crate::structures) fn new(elems: Box<[V]>) -> Self {
23        Self {
24            elems,
25            _marker: PhantomData,
26        }
27    }
28}
29
30impl<K, V> Deref for BoxedMap<K, V>
31where
32    K: TypedIndex,
33{
34    type Target = SliceMap<K, V>;
35    fn deref(&self) -> &SliceMap<K, V> {
36        unsafe { mem::transmute::<&[V], _>(&*self.elems) }
37    }
38}
39
40impl<K, V> DerefMut for BoxedMap<K, V>
41where
42    K: TypedIndex,
43{
44    fn deref_mut(&mut self) -> &mut SliceMap<K, V> {
45        unsafe { mem::transmute::<&mut [V], _>(&mut *self.elems) }
46    }
47}