wasmtime/runtime/resources.rs
1/// A summary of the amount of resources required to instantiate a particular
2/// [`Module`][crate::Module] or [`Component`][crate::component::Component].
3///
4/// Example uses of this information:
5///
6/// * Determining whether your pooling allocator configuration supports
7/// instantiating this module.
8///
9/// * Deciding how many of which `Module` you want to instantiate within a
10/// fixed amount of resources, e.g. determining whether to create 5
11/// instances of module `X` or 10 instances of module `Y`.
12pub struct ResourcesRequired {
13 /// The number of memories that are required.
14 pub num_memories: u32,
15 /// The maximum initial size required by any memory, in units of Wasm pages.
16 pub max_initial_memory_size: Option<u64>,
17 /// The number of tables that are required.
18 pub num_tables: u32,
19 /// The maximum initial size required by any table.
20 pub max_initial_table_size: Option<u64>,
21}
22
23impl ResourcesRequired {
24 #[cfg(feature = "component-model")]
25 pub(crate) fn add(&mut self, other: &ResourcesRequired) {
26 self.num_memories += other.num_memories;
27 self.max_initial_memory_size =
28 core::cmp::max(self.max_initial_memory_size, other.max_initial_memory_size);
29 self.num_tables += other.num_tables;
30 self.max_initial_table_size =
31 core::cmp::max(self.max_initial_table_size, other.max_initial_table_size);
32 }
33}