wasmcloud_runtime/
experimental.rs1use tracing::warn;
2
3#[derive(Copy, Clone, Debug, Default)]
6pub struct Features {
7 pub wasmcloud_messaging_v3: bool,
9 pub workload_identity_interface: bool,
11 pub rpc_interface: bool,
13}
14
15impl Features {
16 #[must_use]
18 pub fn new() -> Self {
19 Self::default()
20 }
21
22 #[must_use]
24 pub fn enable_wasmcloud_messaging_v3(mut self) -> Self {
25 self.wasmcloud_messaging_v3 = true;
26 self
27 }
28
29 #[must_use]
31 pub fn enable_workload_identity_interface(mut self) -> Self {
32 self.workload_identity_interface = true;
33 self
34 }
35
36 #[must_use]
38 pub fn enable_rpc_interface(mut self) -> Self {
39 self.rpc_interface = true;
40 self
41 }
42}
43
44impl std::ops::BitOr for Features {
46 type Output = Self;
47
48 fn bitor(self, rhs: Self) -> Self::Output {
49 Self {
50 wasmcloud_messaging_v3: self.wasmcloud_messaging_v3 || rhs.wasmcloud_messaging_v3,
51 workload_identity_interface: self.workload_identity_interface
52 || rhs.workload_identity_interface,
53 rpc_interface: self.rpc_interface || rhs.rpc_interface,
54 }
55 }
56}
57
58impl std::iter::Sum for Features {
60 fn sum<I: Iterator<Item = Self>>(mut iter: I) -> Self {
61 let first = iter.next().unwrap_or_default();
63 iter.fold(first, |a, b| a | b)
64 }
65}
66
67impl From<&str> for Features {
69 fn from(s: &str) -> Self {
70 match &*s.to_ascii_lowercase() {
71 "wasmcloud-messaging-v3" | "wasmcloud_messaging_v3" => {
72 Self::new().enable_wasmcloud_messaging_v3()
73 }
74 "workload-identity-interface" | "workload_identity_interface" => {
75 Self::new().enable_workload_identity_interface()
76 }
77 "rpc-interface" | "rpc_interface" => Self::new().enable_rpc_interface(),
78 _ => {
79 warn!(%s, "unknown feature flag");
80 Self::new()
81 }
82 }
83 }
84}