Skip to main content

iii_sdk/
lib.rs

1pub mod builtin_triggers;
2pub mod channels;
3pub mod engine;
4pub mod error;
5pub mod helpers;
6pub mod iii;
7pub mod protocol;
8pub mod stream_provider;
9pub mod structs;
10pub mod triggers;
11pub mod types;
12
13/// Public runtime/worker types. (Stage 1 submodule grouping.)
14pub mod runtime {
15    pub use crate::iii::{
16        FunctionInfo, FunctionRef, IIIConnectionState, TriggerInfo, TriggerTypeRef, WorkerInfo,
17        WorkerMetadata,
18    };
19}
20
21/// Public trigger types. (Stage 1 submodule grouping.)
22pub mod trigger {
23    pub use crate::builtin_triggers::IIITrigger;
24    pub use crate::triggers::{Trigger, TriggerConfig, TriggerHandler};
25}
26
27/// Public channel types. (Stage 1 submodule grouping.)
28pub mod channel {
29    pub use crate::channels::{ChannelReader, ChannelWriter, StreamChannelRef};
30    pub use crate::types::Channel;
31}
32
33/// Public error types. (Stage 1 submodule grouping.)
34pub mod errors {
35    pub use crate::error::{Error, InvocationError};
36}
37
38// No `internal` submodule for Rust: the internal types grouped under
39// `iii-sdk/internal` (Node) and `iii.internal` (Python) have no crate-root
40// equivalent here. There is no `InternalHttpRequest` (the Rust SDK uses
41// `iii_helpers::http::HttpRequest`), and the stream result types
42// (`StreamSetResult`, `StreamUpdateResult`, `StreamDeleteResult`) live in `iii_helpers::stream`
43// and are consumed inside `stream_provider.rs`, they are not re-exported at
44// the crate root. Grouping them here would re-surface clean-break helpers
45// types into the SDK, which the `compile_fail` doctests below deliberately
46// forbid. Hence the `internal` grouping is a no-op for Rust.
47
48pub use error::{Error, InvocationError};
49pub use iii::TelemetryOptions;
50pub use iii::{IIIClient, RegisterFunction, RegisterTriggerType};
51pub use iii_helpers::queue::EnqueueResult;
52pub use protocol::{Message, TriggerAction};
53pub use stream_provider::IStream;
54pub use structs::MiddlewareFunctionInput;
55pub use types::{StreamRequest, StreamResponse};
56
57/// Configuration options passed to [`register_worker`].
58///
59/// # Examples
60/// ```rust,no_run
61/// use iii_sdk::{register_worker, InitOptions};
62///
63/// let worker = register_worker("ws://localhost:49134", InitOptions::default());
64/// ```
65#[derive(Debug, Clone, Default)]
66pub struct InitOptions {
67    /// Custom worker metadata. Auto-detected if `None`.
68    pub metadata: Option<iii::WorkerMetadata>,
69    /// Custom HTTP headers sent during the WebSocket handshake.
70    pub headers: Option<std::collections::HashMap<String, String>>,
71    /// OpenTelemetry configuration.
72    pub otel: Option<iii_helpers::observability::OtelConfig>,
73}
74
75/// Create and return a connected SDK instance. The WebSocket connection is
76/// established automatically in a dedicated background thread with its own
77/// tokio runtime.
78///
79/// Call [`IIIClient::shutdown`] before the end of `main` to cleanly stop the
80/// connection and join the background thread. In Rust the process exits
81/// when `main` returns, terminating all threads, so `shutdown()` must be
82/// called while `main` is still running.
83///
84/// # Arguments
85/// * `address` - WebSocket URL of the III engine (e.g. `ws://localhost:49134`).
86/// * `options` - Configuration for worker metadata and OTel.
87///
88/// # Examples
89/// ```rust,no_run
90/// use iii_sdk::{register_worker, InitOptions};
91///
92/// let worker = register_worker("ws://localhost:49134", InitOptions::default());
93/// // register functions, handle events, etc.
94/// worker.shutdown(); // cleanly stops the connection thread
95/// ```
96pub fn register_worker(address: &str, options: InitOptions) -> IIIClient {
97    let InitOptions {
98        metadata,
99        headers,
100        otel,
101    } = options;
102
103    let iii = if let Some(metadata) = metadata {
104        IIIClient::with_metadata(address, metadata)
105    } else {
106        IIIClient::new(address)
107    };
108
109    if let Some(h) = headers {
110        iii.set_headers(h);
111    }
112
113    if let Some(cfg) = otel {
114        iii.set_otel_config(cfg);
115    }
116
117    iii.connect();
118
119    iii
120}
121
122// ---------------------------------------------------------------------------
123// Compile-fail doctests: these enforce that the four channel items relocated
124// to `helpers` are NOT reachable at the crate root. They live here (not in
125// `tests/`) because `cargo test --doc` only picks up doctests inside `src/`.
126// ---------------------------------------------------------------------------
127
128/// ```compile_fail
129/// use iii_sdk::ChannelDirection;
130/// ```
131#[allow(dead_code)]
132fn _ensure_channel_direction_not_top_level() {}
133
134/// ```compile_fail
135/// use iii_sdk::ChannelItem;
136/// ```
137#[allow(dead_code)]
138fn _ensure_channel_item_not_top_level() {}
139
140/// ```compile_fail
141/// use iii_sdk::extract_channel_refs;
142/// ```
143#[allow(dead_code)]
144fn _ensure_extract_channel_refs_not_top_level() {}
145
146/// ```compile_fail
147/// use iii_sdk::is_channel_ref;
148/// ```
149#[allow(dead_code)]
150fn _ensure_is_channel_ref_not_top_level() {}
151
152// ---------------------------------------------------------------------------
153// Compile-fail doctest: enforces that `create_channel` (relocated to
154// `helpers`) is no longer callable on `IIIClient`.
155// ---------------------------------------------------------------------------
156
157/// ```compile_fail
158/// let iii = iii_sdk::IIIClient::new("ws://x");
159/// iii.create_channel(None);
160/// ```
161#[allow(dead_code)]
162fn _ensure_create_channel_not_on_instance() {}
163
164// ---------------------------------------------------------------------------
165// Stage 1 runtime submodule: runtime/worker types are reachable at their new
166// canonical path `iii_sdk::runtime`.
167// ---------------------------------------------------------------------------
168
169/// ```rust,no_run
170/// use iii_sdk::runtime::{
171///     FunctionInfo, FunctionRef, IIIConnectionState, TriggerInfo, TriggerTypeRef, WorkerInfo,
172///     WorkerMetadata,
173/// };
174/// ```
175#[allow(dead_code)]
176fn _ensure_runtime_submodule_path() {}
177
178/// ```compile_fail
179/// use iii_sdk::IIIConnectionState;
180/// ```
181#[allow(dead_code)]
182fn _ensure_connection_state_not_top_level() {}
183
184// ---------------------------------------------------------------------------
185// Stage 1 trigger submodule: trigger types are reachable at their new
186// canonical path `iii_sdk::trigger`.
187// ---------------------------------------------------------------------------
188
189/// ```rust,no_run
190/// use iii_sdk::trigger::{IIITrigger, Trigger, TriggerConfig, TriggerHandler};
191/// ```
192#[allow(dead_code)]
193fn _ensure_trigger_submodule_path() {}
194
195// ---------------------------------------------------------------------------
196// Stage 1 channel submodule: channel types are reachable at their new
197// canonical path `iii_sdk::channel`.
198// ---------------------------------------------------------------------------
199
200/// ```rust,no_run
201/// use iii_sdk::channel::{Channel, ChannelReader, ChannelWriter, StreamChannelRef};
202/// ```
203#[allow(dead_code)]
204fn _ensure_channel_submodule_path() {}
205
206// ---------------------------------------------------------------------------
207// Stage 1 errors submodule: the renamed error type is reachable at its new
208// canonical path `iii_sdk::errors::Error`.
209// ---------------------------------------------------------------------------
210
211/// ```rust,no_run
212/// use iii_sdk::errors::Error;
213/// fn _takes(_e: Error) {}
214/// ```
215#[allow(dead_code)]
216fn _ensure_errors_submodule_path() {}
217
218// ---------------------------------------------------------------------------
219// 0.20 clean break: the deprecated crate-root re-exports and renamed aliases
220// are removed. The relocated types live under their canonical submodule paths
221// (`iii_sdk::{trigger,channel,runtime}`) and the renamed types use their new
222// names (`IIIClient`, `Error`, `TelemetryOptions`).
223// ---------------------------------------------------------------------------
224
225/// ```compile_fail
226/// use iii_sdk::{Channel, ChannelReader, ChannelWriter, StreamChannelRef};
227/// ```
228#[allow(dead_code)]
229fn _ensure_channel_types_not_top_level() {}
230
231/// ```compile_fail
232/// use iii_sdk::{IIITrigger, Trigger, TriggerConfig, TriggerHandler};
233/// ```
234#[allow(dead_code)]
235fn _ensure_trigger_types_not_top_level() {}
236
237/// ```compile_fail
238/// use iii_sdk::{FunctionInfo, FunctionRef, TriggerInfo, TriggerTypeRef, WorkerInfo, WorkerMetadata};
239/// ```
240#[allow(dead_code)]
241fn _ensure_runtime_types_not_top_level() {}
242
243/// ```compile_fail
244/// use iii_sdk::III;
245/// ```
246#[allow(dead_code)]
247fn _ensure_renamed_client_alias_removed() {}
248
249/// ```compile_fail
250/// use iii_sdk::IIIError;
251/// ```
252#[allow(dead_code)]
253fn _ensure_renamed_error_alias_removed() {}
254
255/// ```compile_fail
256/// use iii_sdk::WorkerTelemetryMeta;
257/// ```
258#[allow(dead_code)]
259fn _ensure_renamed_telemetry_alias_removed() {}
260
261// ---------------------------------------------------------------------------
262// Stream types relocated to `iii_helpers::stream`: they are no longer reachable
263// at the crate root, and are reachable from the helpers submodule.
264// ---------------------------------------------------------------------------
265
266/// ```compile_fail
267/// use iii_sdk::{StreamChangeEvent, StreamJoinLeaveEvent};
268/// ```
269#[allow(dead_code)]
270fn _ensure_stream_events_not_top_level() {}
271
272/// ```compile_fail
273/// use iii_sdk::{StreamTriggerConfig, StreamJoinLeaveTriggerConfig};
274/// ```
275#[allow(dead_code)]
276fn _ensure_stream_trigger_configs_not_top_level() {}
277
278/// ```compile_fail
279/// use iii_sdk::{UpdateOp, StreamGetInput};
280/// ```
281#[allow(dead_code)]
282fn _ensure_stream_io_types_not_top_level() {}
283
284/// ```rust,no_run
285/// use iii_helpers::stream::{StreamChangeEvent, StreamJoinLeaveEvent};
286/// fn _takes(_a: StreamChangeEvent, _b: StreamJoinLeaveEvent) {}
287/// ```
288#[allow(dead_code)]
289fn _ensure_stream_events_helpers_path() {}
290
291// ---------------------------------------------------------------------------
292// engine submodule grouping: engine constants and the remote handler type are
293// reachable only at their canonical path `iii_sdk::engine`. Rust folds this
294// grouping into the existing `engine` module (the file `engine.rs`) rather than
295// a separate `pub mod engine { ... }` block, which would clash with it.
296// ---------------------------------------------------------------------------
297
298/// ```rust,no_run
299/// use iii_sdk::engine::{EngineFunctions, EngineTriggers, RemoteFunctionHandler};
300/// let _ = (EngineFunctions::LIST_FUNCTIONS, EngineTriggers::LOG);
301/// fn _takes(_h: RemoteFunctionHandler) {}
302/// ```
303#[allow(dead_code)]
304fn _ensure_engine_submodule_path() {}
305
306/// ```compile_fail
307/// use iii_sdk::{EngineFunctions, EngineTriggers};
308/// ```
309#[allow(dead_code)]
310fn _ensure_engine_constants_not_top_level() {}
311
312/// ```rust,no_run
313/// use iii_sdk::errors::InvocationError;
314/// fn _takes(_e: InvocationError) {}
315/// ```
316#[allow(dead_code)]
317fn _ensure_invocation_error_path() {}
318
319/// ```rust,no_run
320/// use iii_sdk::{StreamRequest, StreamResponse};
321/// fn _takes(_req: StreamRequest, _res: StreamResponse) {}
322/// ```
323#[allow(dead_code)]
324fn _ensure_stream_request_response_path() {}
325
326// ---------------------------------------------------------------------------
327// protocol submodule grouping: the low-level protocol message and
328// register-input types are reachable only at their canonical path
329// `iii_sdk::protocol` and are no longer re-exported at the crate root.
330// ---------------------------------------------------------------------------
331
332/// ```rust,no_run
333/// use iii_sdk::protocol::{
334///     ErrorBody, FunctionMessage, RegisterFunctionMessage, RegisterTriggerInput,
335///     RegisterTriggerMessage, RegisterTriggerTypeMessage, TriggerRequest,
336/// };
337/// ```
338#[allow(dead_code)]
339fn _ensure_protocol_submodule_path() {}
340
341/// ```compile_fail
342/// use iii_sdk::{
343///     ErrorBody, FunctionMessage, RegisterFunctionMessage, RegisterTriggerInput,
344///     RegisterTriggerMessage, RegisterTriggerTypeMessage, TriggerRequest,
345/// };
346/// ```
347#[allow(dead_code)]
348fn _ensure_protocol_types_not_top_level() {}
349
350// ---------------------------------------------------------------------------
351// EnqueueResult is re-exported at the crate root for convenience alongside
352// `TriggerAction`, mirroring its canonical home in `iii_helpers::queue`.
353// ---------------------------------------------------------------------------
354
355/// ```rust,no_run
356/// use iii_sdk::EnqueueResult;
357/// ```
358#[allow(dead_code)]
359fn _ensure_enqueue_result_at_root() {}