it_lilo/traits/
allocatable.rs1use futures::future::BoxFuture;
18use it_memory_traits::MemoryView;
19use thiserror::Error as ThisError;
20
21pub const DEFAULT_MEMORY_INDEX: usize = 0;
22
23pub trait Allocatable<MV: MemoryView<Store>, Store: it_memory_traits::Store>: Send {
24 fn allocate<'this, 'store: 'this, 'store_inner: 'this>(
25 &'this mut self,
26 store: &'store mut <Store as it_memory_traits::Store>::ActualStore<'store_inner>,
27 size: u32,
28 type_tag: u32,
29 ) -> BoxFuture<'this, Result<(u32, MV), AllocatableError>>;
30}
31
32#[derive(Debug, ThisError)]
33pub enum AllocatableError {
34 #[error("memory `{memory_index}` does not exist")]
36 MemoryIsMissing {
37 memory_index: usize,
39 },
40
41 #[error("the allocate function with index `{function_index}` doesn't exist in Wasm module")]
43 AllocateFuncIsMissing {
44 function_index: u32,
46 },
47
48 #[error(r#"call to allocate function was failed: {reason}"#)]
50 AllocateCallFailed {
51 #[source]
53 reason: anyhow::Error,
54 },
55
56 #[error(
58 "allocate func doesn't receive two i32 values,\
59 probably a Wasm module's built with unsupported sdk version"
60 )]
61 AllocateFuncIncompatibleSignature,
62
63 #[error(
65 "allocate func doesn't return a one value of I32 type,\
66 probably a Wasm module's built with unsupported sdk version"
67 )]
68 AllocateFuncIncompatibleOutput,
69
70 #[error("{0}")]
73 UserDefinedError(String),
74}