wasmer_deploy_schema/schema/
memory.rs

1use bytesize::ByteSize;
2use serde::{Deserialize, Serialize};
3use uuid::Uuid;
4
5use super::Merge;
6
7/// Memory settings.
8#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug, schemars::JsonSchema)]
9pub struct CapabilityMemoryV1 {
10    /// Memory limit for an instance.
11    ///
12    /// Format: [digit][unit], where unit is Mb/Gb/MiB/GiB,...
13    #[schemars(with = "Option<String>")]
14    #[serde(skip_serializing_if = "Option::is_none")]
15    pub limit: Option<ByteSize>,
16}
17
18impl Merge for CapabilityMemoryV1 {
19    fn merge_extend(self, other: &Self) -> Self {
20        Self {
21            limit: self.limit.merge_extend(&other.limit),
22        }
23    }
24}
25
26/// Determines the "swappiness" of memory.
27#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug, schemars::JsonSchema)]
28pub enum MemorySwappinessV1 {
29    /// Always allow the memory to be swapped to disk.
30    #[serde(rename = "always")]
31    Always,
32    /// Never allow the memory to be swapped to disk.
33    #[serde(rename = "never")]
34    Never,
35}
36
37impl Merge for MemorySwappinessV1 {
38    fn merge_extend(self, _other: &Self) -> Self {
39        self
40    }
41}
42
43/// Configuration for swap memory.
44#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug, schemars::JsonSchema)]
45pub struct CapabilityMemorySwapV1 {
46    #[serde(skip_serializing_if = "Option::is_none")]
47    pub swappiness: Option<MemorySwappinessV1>,
48    /// A unique id for the memory.
49    ///
50    /// Only useful for shared memories.
51    #[serde(skip_serializing_if = "Option::is_none")]
52    pub memory_id: Option<Uuid>,
53    #[schemars(with = "String")]
54    #[serde(skip_serializing_if = "Option::is_none")]
55    pub maximum_size: Option<ByteSize>,
56}
57
58impl Merge for CapabilityMemorySwapV1 {
59    fn merge_extend(self, other: &Self) -> Self {
60        Self {
61            swappiness: self.swappiness.merge_extend(&other.swappiness),
62            memory_id: self.memory_id.merge_extend(&other.memory_id),
63            maximum_size: self.maximum_size.merge_extend(&other.maximum_size),
64        }
65    }
66}
67
68#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug, schemars::JsonSchema)]
69pub struct CapabilityPersistentMemoryV1 {
70    /// Volumes to be mounted inside memory.
71    // TODO: use a `VolumeConfig` type here.
72    #[serde(default)]
73    pub volumes: Vec<()>,
74}
75
76impl Merge for CapabilityPersistentMemoryV1 {
77    fn merge_extend(self, _other: &Self) -> Self {
78        self
79    }
80}