fuel_vm/
pool.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//! Pool of VM memory instances for reuse.

use crate::interpreter::Memory;

#[cfg(any(test, feature = "test-helpers"))]
use crate::interpreter::MemoryInstance;

/// Trait for a VM memory pool.
pub trait VmMemoryPool: Sync {
    /// The memory instance returned by this pool.
    type Memory: Memory + Send + Sync + 'static;

    /// Gets a new VM memory instance from the pool.
    fn get_new(&self) -> impl core::future::Future<Output = Self::Memory> + Send;
}

/// Dummy pool that just returns new instance every time.
#[cfg(any(test, feature = "test-helpers"))]
#[derive(Default, Clone)]
pub struct DummyPool;

#[cfg(any(test, feature = "test-helpers"))]
impl VmMemoryPool for DummyPool {
    type Memory = MemoryInstance;

    fn get_new(&self) -> impl core::future::Future<Output = Self::Memory> + Send {
        core::future::ready(MemoryInstance::new())
    }
}