Skip to main content

Installation

Initialization

register_worker

Signature

Parameters

&str
required
InitOptions
required

Methods

register_function

Register a function with the engine. Argument order matches the Node and Python SDKs: (id, registration). Signature
impl Into<String>
required
Unique identifier for the function.
RegisterFunction
required
Built via [RegisterFunction::new], [RegisterFunction::new_async], or [RegisterFunction::http]. Chain .description(...), .metadata(...), .request_format(...), .response_format(...) as needed.

call

Call a function: resolves to its result. The routing behavior depends on the action field of the request:
  • No action: synchronous, waits for the function to return.
  • CallAction::Enqueue: async via named queue.
  • CallAction::Void: fire-and-forget.
A function this worker registered itself runs in-process once the engine allowed it (“local dispatch”, see Dispatch): same result, error shape and timeout, and nothing on the wire unless an observer’s filters match the call. A sync handler then runs inline on the caller’s task, where the timeout cannot interrupt it: a sync handler that can block should be async, or registered with RegisterFunction::local_dispatch(false). CallRequest::dispatch with Dispatch::Remote forces the engine path. Calls made from inside a handler (or a deliver hook) carry that handler’s invocation as their caller. A request built with CallRequest::observer calls through that observer: the engine runs its target with the payload, as given. Signature
impl Into<CallRequestWithMetadata>
required

observe

Observes source and calls target once per matching call. source is a Source, or a function id for every successful call with the defaults. Returns at once, before the engine answered: the handle starts pending; ObserverHandle::ready resolves on active and fails on error (INVALID_ARGS, INVALID_FILTER, FORBIDDEN, NOT_OBSERVABLE, an added hook’s rejection, UNSUPPORTED against an engine without observe). There is no inline handler: target is a registered function, and the observer stays pending until it is registered. Signature

Parameters

impl Into<Source>
required
impl Into<Target>
required

trigger

Deprecated since 0.26.0. Use call.
call under its 0.25 name. Signature

Parameters

impl Into<CallRequestWithMetadata>
required

clear_observation_deliver_for

Removes the deliver hook of function_id: iii delivers its calls. Signature

Parameters

&str
required

clear_observation_match_for

Removes the match hook of function_id: every observer wants every call. Signature

Parameters

&str
required

clear_observer_added

Removes the added hook set with on_observer_added. Signature

clear_observer_added_for

Removes the added hook of function_id. Signature

Parameters

&str
required

clear_observer_removed

Removes the removed hook set with on_observer_removed. Signature

clear_observer_removed_for

Removes the removed hook of function_id. Signature

Parameters

&str
required

engine_supports_observe

Whether the engine on the current connection supports observe: it advertised observe.v1 in its WorkerRegistered. None until that arrives, before the first connection and again while reconnecting. Without it, observe() fails with UNSUPPORTED and the hooks of this worker’s functions never run; a worker can keep a fallback for older engines when this is Some(false). Pair it with on_engine_supports_observe to follow changes across reconnects. Signature

Example


fatal_error

Fatal error that stopped the worker, if any. Set when the engine rejects registration (see Error::RegistrationRejected); the worker does not reconnect once this is populated. Signature

get_connection_state

Get the current connection state. Signature

Example


is_observed

Whether function_id, a function this worker hosts, has any active observer. Signature

Parameters

&str
required

is_observed_for

Whether call of function_id would reach any observer; see FunctionRef::is_observed_for. Signature

Parameters

&str
required
&Call
required

namespace

The effective worker namespace (resolved from InitOptions.namespace / III_NAMESPACE), or None for the engine’s default. Signature

observe_with

observe with the observer’s id, policy and metadata. An id (ObserverOptions::id) that a handle of this client holds, in any state, is refused at the call: nothing is sent, the holding handle and its observer are untouched, and the handle returned is in state error with the reason OBSERVER_ID_CONFLICT, observer id already in use: <id>. Its ready fails with that code, and its dispose sends nothing. The id is free again as soon as dispose() is called on the handle that held it, before the engine confirms the disposal. The engine answers a connection’s observes in the order it reads them, so each handle of the id gets the answers to its own observe and unobserve: a late disposed for the earlier observer never disposes the new one. Signature

Parameters

impl Into<Source>
required
impl Into<Target>
required
ObserverOptions
required

observers

The active observers of function_id, a function this worker hosts. Signature

Parameters

&str
required

on_engine_supports_observe

Calls listener with the engine’s observe support (see engine_supports_observe) when it becomes known and whenever a later connection’s WorkerRegistered changes it (an engine upgraded or rolled back between reconnects). Not called for a reconnect to an engine that says the same, nor while reconnecting (the value is unknown then, not changed). A listener is called with the current value right away when it is known; one added while it is not (before the first connection, while reconnecting) hears it from the next WorkerRegistered, the same value or not. Either way it sees every value from the current one on, in order. Listeners run on the same thread as ObserverHandle::on_state_change listeners, never on the connection’s read loop: one may call the client. Signature
F
required

on_observation_deliver_for

Delivers each call of function_id with hook, which decides which observers get it and what its caller gets back; iii delivers nothing for the function. See DeliverHook. A function with a deliver hook needs an engine that advertised observe.v2: against an older one it stays unregistered, and the SDK logs UNSUPPORTED once. Signature

Parameters

&str
required
impl DeliverHook
required

on_observation_match_for

Says which calls of function_id each observer wants; see Match. Set while observers are active, a key index is rebuilt from them. A function with a match hook needs an engine that advertised observe.v2: against an older one it stays unregistered, and the SDK logs UNSUPPORTED once. Signature

Parameters

&str
required
Match
required

on_observer_added

Runs hook when an observer is added to any function this worker hosts, before the function’s own added hook. Returns the client, for chaining. Signature

Parameters

impl AddedHook
required

on_observer_added_for

Runs hook when an observer is added to function_id, after the worker’s added hook. Set it before registering the function: then it runs for every observer. Signature

Parameters

&str
required
impl AddedHook
required

on_observer_removed

Runs hook when an observer of any function this worker hosts is removed, after the function’s own removed hook. Signature

Parameters

impl RemovedHook
required

on_observer_removed_for

Runs hook when an observer of function_id is removed, before the worker’s removed hook. Signature

Parameters

&str
required
impl RemovedHook
required

set_namespace

Override the worker’s target namespace (call before connect). Applied by register_worker after resolving InitOptions.namespace and III_NAMESPACE. Signature

Parameters

impl Into<String>
required

shutdown

Shutdown the III client and wait for the connection thread to finish. This stops the connection loop, sends a shutdown signal, and joins the background connection thread. OpenTelemetry is flushed inside the connection thread before it exits. Signature

Example


shutdown_async

Shutdown the III client. This stops the connection loop and sends a shutdown signal, but it does not join connection_thread. This method returns without waiting for run_connection() to finish, making it safe to call from an async context without stalling the executor; shutdown blocks and joins the thread. The OpenTelemetry flush (telemetry::shutdown_otel()) still runs inside the connection thread after run_connection() returns, so it may not complete unless shutdown is used to join the thread. Signature

Example


wait_until_registered

Wait until the engine accepts this worker’s initial registration. Returns Error::RegistrationRejected for a fatal identity conflict, Error::Timeout when the deadline expires, and Error::NotConnected when called before the client starts or after it stops. Signature

Parameters

Duration
required

Functions

capture_fires

Signature

Parameters

&[Capture]
required
bool
required

current_invocation

The invocation the calling task is running for, or None outside any handler (and in a task spawned from a handler without scope). Signature

scope

Runs fut with ctx as its current invocation. Use it to keep the handler’s context in a task it spawns; None runs fut outside any invocation. The local-call nesting of the calling task is carried too, so recursing through spawned tasks stays bounded. Signature

Parameters

impl Into<Option<InvocationCtx>>
required
F
required

Types

iii_sdk

EnqueueResult · InitOptions · ObserveSupportListener · RegisterFunction · TelemetryOptions

EnqueueResult

Result returned when a function is called with CallAction::Enqueue.

InitOptions

Configuration options passed to register_worker.

ObserveSupportListener

A listener added with IIIClient::on_engine_supports_observe.

RegisterFunction

Function registration builder. The function ID is supplied separately at registration time via IIIClient::register_function, RegisterFunction only carries the handler and optional metadata. Constructors:
  • RegisterFunction::new: sync function. Accepts both typed handlers (schemas auto-extracted via schemars) and Fn(Value, Option<Value>) -> Result<Value, Error> closures. The second argument is the per-invocation metadata sidecar and is None when absent. A Value input or result passes as is; other types go through serde.
  • RegisterFunction::new_async: async equivalent of new.
  • RegisterFunction::http: function invoked over HTTP (Lambda, Cloudflare Workers, etc.).
Builder methods (all consume self):
  • description
  • metadata
  • request_format: overrides any auto-extracted schema.
  • response_format: overrides any auto-extracted schema; it describes what observers observe.
  • args_format: the observers’ args.
  • private: only this worker calls it.
  • observable: false refuses every observer.
  • local_dispatch: opt out of in-process calls.
The handler’s return value is what observers observe. An event source’s handler returns the event it is called with. What the worker does when the function is observed is set with hooks: see hooks.

TelemetryOptions

Worker metadata reported to the engine (language, framework, project).

iii_sdk::channel

Channel · ChannelReader · ChannelWriter · StreamChannelRef

Channel

A streaming channel pair for worker-to-worker data transfer.

ChannelReader

WebSocket-backed reader for streaming binary data and text messages.

ChannelWriter

WebSocket-backed writer for streaming binary data and text messages.

StreamChannelRef

iii_sdk::channels

ChannelDirection · ChannelItem

ChannelDirection


ChannelItem

iii_sdk::context

InvocationCtx

InvocationCtx

The invocation a handler is running for.

iii_sdk::engine

EngineFunctions · EngineSources

EngineFunctions

Engine function ids for internal operations.

EngineSources

The ids of the engine-hosted sources: private functions the engine calls once per event, whose handler returns the event. Observe them with filters on their input:

iii_sdk::errors

Error · InvocationError

Error

Errors returned by the III SDK.

InvocationError

Structured invocation failure, mirroring the Node and Python InvocationError. Produced from the Error::Remote variant via Error::invocation_error. function_id is None from that accessor because the wire Remote payload does not carry it.

iii_sdk::hooks

AddedHook · Call · DeliverHook · Keys · Match · RemovedHook

AddedHook

Runs when an observer is added to a function this worker hosts, before the SDK accepts it: what it sets up is in place before the observer’s first call. Returning an error rejects the observer: an ObserveRejection sets the code, any other error (? on an Error, a failed call’s included) is OBSERVE_REJECTED, and a hook still running after 30 s is OWNER_TIMEOUT. Implemented for async closures taking the Observer by value. Implement with plain async fn, without #[async_trait]. The returned future is Send and may borrow self across .await. This trait is not dyn-compatible; pass a concrete hook to IIIClient::on_observer_added.

Call

One call of a function this worker hosts, as its observers observe it. output is the handler’s return value: what observers observe. A source that asks FunctionRef::is_observed_for before calling fills in only what its Match::keys read:

DeliverHook

Delivers each call of one function itself, in place of iii’s delivery: what it returns (or fails with) is the call’s result, and iii delivers nothing for the function. For a function whose observers’ answers matter (an HTTP route’s response, a queue subscriber’s ack) or whose calls each go to one observer, called through with CallRequest::observer. It runs after the handler, inside the function’s invocation context and span, so calls it makes have the function’s invocation as their caller. It receives the call and the observers that matched it (Match, or all of them), a snapshot taken when the call started. It applies their filters with Observer::matches. Implemented for async closures taking (Call, Vec<Observer>). Implement with plain async fn, without #[async_trait]. The returned future is Send and may borrow self across .await. This trait is not dyn-compatible; pass a concrete hook to IIIClient::on_observation_deliver_for.

Keys

The keys an observer is filed under, or a call matches, for Match::keys: none, one or several. Converts from &str, String, their Options and Vecs. Keys borrowed from the observer or the call cost no allocation.

Match

Which calls of a function each observer wants: the function’s match hook (IIIClient::on_observation_match_for). A worker sets it when its observers’ args say which calls they want; iii does everything else as usual: the observers’ capture, filters and policy still apply. IIIClient::clear_observation_match_for removes it: every observer wants every call again.

RemovedHook

Runs once for every accepted observer when it is removed (unobserved, disposed, rejected late), to tear down what AddedHook set up. It never runs for an observer that was not accepted. A panic is logged; the observer is removed either way. Implemented for async closures taking the Observer by value. Implement with plain async fn, without #[async_trait]. The returned future is Send and may borrow self across .await. This trait is not dyn-compatible; pass a concrete hook to IIIClient::on_observer_removed.

iii_sdk::observable

Observer · ObserveRejection

Observer

One observer of a function this worker hosts, as its host sees it: its id, args, filters, target and capture. Never its metadata, policy or observing worker. Cheap to clone (an Arc), so hooks take it by value and a worker keeps it in its own index. Two Observers are equal when their ids are. The engine may announce an observer again with the same args and other filters, target or capture: it stays the same observer and no hook runs. Handles given out earlier keep the view they were made with, and IIIClient::observers returns the announced one.

ObserveRejection

An AddedHook’s refusal of an observer, with the code the observer’s ready() fails with. Any other error is OBSERVE_REJECTED.

iii_sdk::observe

Observed · ObservedError · ObserverHandle · ObserverOptions · ObserverReason · ObserverStatus · Source · StateListener · Target

Observed

What an observer’s target receives when iii delivers: the observed call, per the observer’s capture.

ObservedError

What a call failed with: Observed::error, Call::error.

ObserverHandle

Handle to an observer created by IIIClient::observe. Cheap to clone. The observer exists until dispose (or its policy runs out); dropping the handle does not remove it. It works before the connection is up and is replayed with the same id after a reconnect.

ObserverOptions

The observer itself: its id, policy and metadata sidecar.

ObserverReason

Why an observer is in its state: { code, message }.

ObserverStatus

An observer’s state, why, and how often it fired.

Source

The left side of an observer: what is observed.

StateListener

A listener added with ObserverHandle::on_state_change.

Target

The right side of an observer: a registered function.

iii_sdk::protocol

Activation · CallAction · Caller · CallRequest · CallRequestWithMetadata · Capture · Dispatch · DroppedReportStats · ErrorBody · FunctionMessage · InvocationStatus · LocalFunctionStats · Message · ObservedItem · ObserverState · ObserverView · ObserveSource · ObserveTarget · ParentCaller · RegisterFunctionMessage

Activation

invokefunction.activation.

CallAction

Routing action for CallRequest. Determines how the engine handles the invocation.
  • Enqueue: Routes through a named queue for async processing.
  • Void: Fire-and-forget, no response.

Caller

Who made an invocation. worker_id / worker_name are stamped by the engine from the calling connection; function_id, invocation_id and parent are asserted by the calling SDK.

CallRequest

Request object for IIIClient::call.

CallRequestWithMetadata

A CallRequest plus optional per-invocation metadata, target namespace, dispatch and the observer it is made through.

Capture

What an activation ships to the target. A filter may read any root, whatever is captured.

Dispatch

Which path IIIClient::call takes. A call to a function registered by this same worker runs in-process (“local dispatch”) when all of these hold:
  1. the function has a handler here (not RegisterFunction::http) and was not registered with RegisterFunction::local_dispatch(false);
  2. the engine confirmed it with functionregistered { local_dispatch: true };
  3. the call resolves to the namespace the function is registered in;
  4. the action is not CallAction::Enqueue (a Void call runs locally, fire-and-forget);
  5. the dispatch is not Dispatch::Remote, and the call is not made through an observer (CallRequest::observer).
Otherwise the call goes through the engine. A local call returns the same result, error shape and timeout as a remote one, and is reported to the engine only when an observer’s filters match it.

DroppedReportStats

SDK-side report drops in localinvocationstats.

ErrorBody


FunctionMessage


InvocationStatus

Outcome of an observed call.

LocalFunctionStats

Per-function counts in localinvocationstats.

Message


ObservedItem

One item of invocationsobserved: one local call and the observers iii’s delivery selected for it. input / output / error / metadata keep null apart from absent.

ObserverState

Observer lifecycle states.

ObserverView

An observer as its function’s host sees it (functionregistered, observeradded): never the observer’s metadata, policy or observing worker.

ObserveSource

The left side of iii.observe on the wire. Absent fields stay absent; the engine applies the defaults.

ObserveTarget

The right side of iii.observe on the wire: a registered function.

ParentCaller

Caller::parent: a caller without a parent of its own.

RegisterFunctionMessage

iii_sdk::runtime

FunctionInfo · FunctionRef · IIIConnectionState · WorkerIdentityMode · WorkerInfo · WorkerMetadata

FunctionInfo

Function information returned by engine::functions::list

FunctionRef

A function this worker registered, returned by IIIClient::register_function. Its hook methods are the client’s, with the function id filled in; each returns the receiver, for chaining.

IIIConnectionState

Connection state for the III WebSocket client

WorkerIdentityMode

Selects where a worker connection gets its engine identity.

WorkerInfo

Worker information returned by engine::workers::list

WorkerMetadata

Worker metadata for auto-registration

iii_sdk::structs

MiddlewareFunctionInput

MiddlewareFunctionInput

Input passed to the RBAC middleware function on every function invocation through the RBAC port. The middleware can inspect, modify, or reject the call before it reaches the target function.

iii_sdk::types

RemoteFunctionData · RemoteFunctionHandler · StreamRequest · StreamResponse

RemoteFunctionData


RemoteFunctionHandler

A dispatchable function handler. Receives the invocation payload. Handlers that also want the optional per-invocation metadata sidecar use RemoteFunctionHandlerWithMetadata; this single-argument shape is kept for backward compatibility.

StreamRequest

Incoming streaming request received by a function that serves HTTP. Alias of iii_helpers::http::HttpRequest.

StreamResponse

Streaming response type, mirroring the Node and Python StreamResponse. Alias of iii_helpers::http::HttpResponse; added for cross-language parity.