wasmcloud_control_interface/
lib.rs1use serde::{Deserialize, Serialize};
21
22mod broker;
23mod otel;
24
25pub mod client;
26pub use client::{Client, ClientBuilder};
27
28mod types;
29pub use types::component::*;
30pub use types::ctl::*;
31pub use types::host::*;
32pub use types::link::*;
33pub use types::provider::*;
34pub use types::registry::*;
35pub use types::rpc::*;
36
37#[deprecated(
41 since = "2.3.0",
42 note = "String type aliases are deprecated, use Strings instead"
43)]
44#[allow(dead_code)]
45mod aliases {
46 type ComponentId = String;
47 type KnownConfigName = String;
48 type LatticeTarget = String;
49 type LinkName = String;
50 type WitInterface = String;
51 type WitNamespace = String;
52 type WitPackage = String;
53}
54#[allow(unused_imports)]
55#[allow(deprecated)]
56pub use aliases::*;
57
58type Result<T> = ::core::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
60
61#[allow(unused)]
63pub(crate) enum IdentifierKind {
64 HostId,
66 ComponentId,
68 ComponentRefs,
70 ProviderRef,
72 LinkName,
74}
75
76impl IdentifierKind {
77 fn is_host_id(value: impl AsRef<str>) -> Result<String> {
79 assert_non_empty_string(value, "Host ID cannot be empty")
80 }
81
82 fn is_component_id(value: impl AsRef<str>) -> Result<String> {
84 assert_non_empty_string(value, "Component ID cannot be empty")
85 }
86
87 fn is_component_ref(value: impl AsRef<str>) -> Result<String> {
89 assert_non_empty_string(value, "Component OCI reference cannot be empty")
90 }
91
92 fn is_provider_ref(value: impl AsRef<str>) -> Result<String> {
94 assert_non_empty_string(value, "Provider OCI reference cannot be empty")
95 }
96
97 fn is_provider_id(value: impl AsRef<str>) -> Result<String> {
99 assert_non_empty_string(value, "Provider ID cannot be empty")
100 }
101
102 fn is_link_name(value: impl AsRef<str>) -> Result<String> {
104 assert_non_empty_string(value, "Link Name cannot be empty")
105 }
106}
107
108pub(crate) fn json_serialize<T>(item: T) -> Result<Vec<u8>>
110where
111 T: Serialize,
112{
113 serde_json::to_vec(&item).map_err(|e| format!("JSON serialization failure: {e}").into())
114}
115
116pub(crate) fn json_deserialize<'de, T: Deserialize<'de>>(buf: &'de [u8]) -> Result<T> {
118 serde_json::from_slice(buf).map_err(|e| format!("JSON deserialization failure: {e}").into())
119}
120
121fn assert_non_empty_string(input: impl AsRef<str>, message: impl AsRef<str>) -> Result<String> {
123 let input = input.as_ref();
124 let message = message.as_ref();
125 if input.trim().is_empty() {
126 Err(message.into())
127 } else {
128 Ok(input.trim().to_string())
129 }
130}