-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmod.rs
More file actions
70 lines (53 loc) · 2.17 KB
/
mod.rs
File metadata and controls
70 lines (53 loc) · 2.17 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use std::collections::HashMap;
use anyhow::Context;
use async_trait::async_trait;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use crate::{LoadPath, fs::read, manifest::CanisterManifest, prelude::*};
pub mod assets;
pub mod build;
pub mod prebuilt;
pub mod recipe;
pub mod script;
pub mod sync;
/// Canister settings, such as compute and memory allocation.
#[derive(Clone, Debug, Default, Deserialize, PartialEq, JsonSchema, Serialize)]
pub struct Settings {
/// Compute allocation (0 to 100). Represents guaranteed compute capacity.
pub compute_allocation: Option<u64>,
/// Memory allocation in bytes. If unset, memory is allocated dynamically.
pub memory_allocation: Option<u64>,
/// Freezing threshold in seconds. Controls how long a canister can be inactive before being frozen.
pub freezing_threshold: Option<u64>,
/// Reserved cycles limit. If set, the canister cannot consume more than this many cycles.
pub reserved_cycles_limit: Option<u64>,
/// Wasm memory limit in bytes. Sets an upper bound for Wasm heap growth.
pub wasm_memory_limit: Option<u64>,
/// Wasm memory threshold in bytes. Triggers a callback when exceeded.
pub wasm_memory_threshold: Option<u64>,
/// Environment variables for the canister as key-value pairs.
/// These variables are accessible within the canister and can be used to configure
/// behavior without hardcoding values in the WASM module.
pub environment_variables: Option<HashMap<String, String>>,
}
#[derive(Debug, thiserror::Error)]
pub enum LoadPathError {
#[error("failed to read canister manifest")]
Read,
#[error("failed to deserialize canister manifest")]
Deserialize,
#[error(transparent)]
Unexpected(#[from] anyhow::Error),
}
pub struct PathLoader;
#[async_trait]
impl LoadPath<CanisterManifest, LoadPathError> for PathLoader {
async fn load(&self, path: &Path) -> Result<CanisterManifest, LoadPathError> {
// Read file
let mbs = read(path).context(LoadPathError::Read)?;
// Load YAML
let m =
serde_yaml::from_slice::<CanisterManifest>(&mbs).context(LoadPathError::Deserialize)?;
Ok(m)
}
}