spin_trigger/cli/
max_instance_memory.rs

1use spin_core::async_trait;
2use spin_factors::RuntimeFactors;
3use spin_factors_executor::{ExecutorHooks, FactorsInstanceBuilder};
4
5/// An [`ExecutorHooks`] that sets the maximum memory allocation limit.
6pub struct MaxInstanceMemoryHook {
7    max_instance_memory: usize,
8}
9
10impl MaxInstanceMemoryHook {
11    pub fn new(max_instance_memory: usize) -> Self {
12        Self {
13            max_instance_memory,
14        }
15    }
16}
17
18#[async_trait]
19impl<F: RuntimeFactors, U> ExecutorHooks<F, U> for MaxInstanceMemoryHook {
20    fn prepare_instance(&self, builder: &mut FactorsInstanceBuilder<F, U>) -> anyhow::Result<()> {
21        builder
22            .store_builder()
23            .max_memory_size(self.max_instance_memory);
24        Ok(())
25    }
26}