wasmcloud_host/wasmbus/
experimental.rs1use tracing::warn;
2
3#[derive(Copy, Clone, Debug, Default)]
6pub struct Features {
7 pub(crate) builtin_http_client: bool,
10 pub(crate) builtin_http_server: bool,
13 pub(crate) builtin_messaging_nats: bool,
16 pub(crate) wasmcloud_messaging_v3: bool,
18 pub(crate) workload_identity_auth: bool,
21 pub(crate) workload_identity_interface: bool,
23 pub(crate) rpc_interface: bool,
25}
26
27impl Features {
28 pub fn new() -> Self {
30 Self::default()
31 }
32
33 pub fn enable_builtin_http_client(mut self) -> Self {
35 self.builtin_http_client = true;
36 self
37 }
38
39 pub fn enable_builtin_http_server(mut self) -> Self {
41 self.builtin_http_server = true;
42 self
43 }
44
45 pub fn enable_builtin_messaging_nats(mut self) -> Self {
47 self.builtin_messaging_nats = true;
48 self
49 }
50
51 pub fn enable_wasmcloud_messaging_v3(mut self) -> Self {
53 self.wasmcloud_messaging_v3 = true;
54 self
55 }
56
57 pub fn enable_workload_identity_auth(mut self) -> Self {
59 self.workload_identity_auth = true;
60 self
61 }
62
63 pub fn enable_workload_identity_interface(mut self) -> Self {
65 self.workload_identity_interface = true;
66 self
67 }
68
69 pub fn enable_rpc_interface(mut self) -> Self {
71 self.rpc_interface = true;
72 self
73 }
74}
75
76impl std::ops::BitOr for Features {
78 type Output = Self;
79
80 fn bitor(self, rhs: Self) -> Self::Output {
81 Self {
82 builtin_http_client: self.builtin_http_client || rhs.builtin_http_client,
83 builtin_http_server: self.builtin_http_server || rhs.builtin_http_server,
84 builtin_messaging_nats: self.builtin_messaging_nats || rhs.builtin_messaging_nats,
85 wasmcloud_messaging_v3: self.wasmcloud_messaging_v3 || rhs.wasmcloud_messaging_v3,
86 workload_identity_auth: self.workload_identity_auth || rhs.workload_identity_auth,
87 workload_identity_interface: self.workload_identity_interface
88 || rhs.workload_identity_interface,
89 rpc_interface: self.rpc_interface || rhs.rpc_interface,
90 }
91 }
92}
93
94impl std::iter::Sum for Features {
96 fn sum<I: Iterator<Item = Self>>(mut iter: I) -> Self {
97 let first = iter.next().unwrap_or_default();
99 iter.fold(first, |a, b| a | b)
100 }
101}
102
103impl From<&str> for Features {
105 fn from(s: &str) -> Self {
106 match &*s.to_ascii_lowercase() {
107 "builtin-http-client" | "builtin_http_client" => {
108 Self::new().enable_builtin_http_client()
109 }
110 "builtin-http-server" | "builtin_http_server" => {
111 Self::new().enable_builtin_http_server()
112 }
113 "builtin-messaging-nats" | "builtin_messaging_nats" => {
114 Self::new().enable_builtin_messaging_nats()
115 }
116 "wasmcloud-messaging-v3" | "wasmcloud_messaging_v3" => {
117 Self::new().enable_wasmcloud_messaging_v3()
118 }
119 "workload-identity-auth" | "workload_identity_auth" => {
120 Self::new().enable_workload_identity_auth()
121 }
122 "workload-identity-interface" | "workload_identity_interface" => {
123 Self::new().enable_workload_identity_interface()
124 }
125 "rpc-interface" | "rpc_interface" => Self::new().enable_rpc_interface(),
126 _ => {
127 warn!(%s, "unknown feature flag");
128 Self::new()
129 }
130 }
131 }
132}
133
134impl From<Features> for wasmcloud_runtime::experimental::Features {
136 fn from(f: Features) -> wasmcloud_runtime::experimental::Features {
137 wasmcloud_runtime::experimental::Features {
138 wasmcloud_messaging_v3: f.wasmcloud_messaging_v3,
139 workload_identity_interface: f.workload_identity_interface,
140 rpc_interface: f.rpc_interface,
141 }
142 }
143}