fuel_vm/
pool.rs

1//! Pool of VM memory instances for reuse.
2
3use crate::interpreter::Memory;
4
5#[cfg(any(test, feature = "test-helpers"))]
6use crate::interpreter::MemoryInstance;
7
8/// Trait for a VM memory pool.
9pub trait VmMemoryPool: Sync {
10    /// The memory instance returned by this pool.
11    type Memory: Memory + Send + Sync + 'static;
12
13    /// Gets a new VM memory instance from the pool.
14    fn get_new(&self) -> impl core::future::Future<Output = Self::Memory> + Send;
15}
16
17/// Dummy pool that just returns new instance every time.
18#[cfg(any(test, feature = "test-helpers"))]
19#[derive(Default, Clone)]
20pub struct DummyPool;
21
22#[cfg(any(test, feature = "test-helpers"))]
23impl VmMemoryPool for DummyPool {
24    type Memory = MemoryInstance;
25
26    fn get_new(&self) -> impl core::future::Future<Output = Self::Memory> + Send {
27        core::future::ready(MemoryInstance::new())
28    }
29}