wasmer_wasix/
capabilities.rs1use std::time::Duration;
2
3use crate::http::HttpClientCapabilityV1;
4
5#[derive(Clone, Debug, PartialEq, Eq, Hash)]
7pub struct Capabilities {
8 pub insecure_allow_all: bool,
9 pub http_client: HttpClientCapabilityV1,
10 pub threading: CapabilityThreadingV1,
11}
12
13impl Capabilities {
14 pub fn new() -> Self {
15 Self {
16 insecure_allow_all: false,
17 http_client: Default::default(),
18 threading: Default::default(),
19 }
20 }
21
22 pub fn update(&mut self, other: Capabilities) {
25 let Capabilities {
26 insecure_allow_all,
27 http_client,
28 threading,
29 } = other;
30 self.insecure_allow_all |= insecure_allow_all;
31 self.http_client.update(http_client);
32 self.threading.update(threading);
33 }
34}
35
36impl Default for Capabilities {
37 fn default() -> Self {
38 Self::new()
39 }
40}
41
42#[derive(Debug, Default, Clone, PartialEq, Eq, Hash)]
44pub struct CapabilityThreadingV1 {
45 pub max_threads: Option<usize>,
49
50 pub enable_asynchronous_threading: bool,
53
54 pub enable_exponential_cpu_backoff: Option<Duration>,
59
60 pub enable_blocking_sleep: bool,
63}
64
65impl CapabilityThreadingV1 {
66 pub fn update(&mut self, other: CapabilityThreadingV1) {
67 let CapabilityThreadingV1 {
68 max_threads,
69 enable_asynchronous_threading,
70 enable_exponential_cpu_backoff,
71 enable_blocking_sleep,
72 } = other;
73 self.enable_asynchronous_threading |= enable_asynchronous_threading;
74 if let Some(val) = enable_exponential_cpu_backoff {
75 self.enable_exponential_cpu_backoff = Some(val);
76 }
77 self.max_threads = max_threads.or(self.max_threads);
78 self.enable_blocking_sleep |= enable_blocking_sleep;
79 }
80}