Skip to main content

Crate ice_rpc_rx

Crate ice_rpc_rx 

Source
Expand description

Reactive layer of ice-rpc: the stream vocabulary, the operators, the multicast primitive and the execution facade they need.

This crate is the foundation of ice-rpc. It owns Observable, Event, ObservableError and RpcError, and it knows nothing about the wire: no framing, no serialization format, no transport. ice-rpc depends on it and re-exports every item under its historical path, so a consumer of ice-rpc sees one single stream type and imports nothing new.

ModuleContents
eventEvent, ObservableError and the producer-side Sender
streamObservable and the local channel constructors
errorRpcError, the technical error of the whole stack
creationfrom, of, throw_error, defer, from_future, ObservableInput
subjectSubject, the multicast source
subscribeSubscription, the cancellation handle — and the Future awaited to join it
transformthe operators carried by Observable
rtexecution facade and CancellationToken

The operators are inherent methods on Observable: no extension trait to import, one single stream type from the first operator to the last.

ⓘ
// `stream` is the native type returned by an ice-rpc service.
let stream: ice_rpc_rx::Observable<i32, String> = proxy.foo().await;

let odds = stream.filter(|v| *v % 2 == 1).map(|v| v * 10).take(5);
let first = odds.first_value().await?;
  • Observable — the operators (map, filter, distinct_until_changed, map_err, scan, switch_map, take, skip, first, first_with, merge, start_with, tap, finalize, delay, timeout, catch_error, take_until, take_until_token) and the terminals (first_value, last_value, collect, for_each, subscribe, subscribe_all, next, recv). Every operator is a pull-based combinator: no intermediate channel, no spawned task. Each has its own reference, with a runnable example, on Observable.
  • Subject — the push side: a multi-producer / multi-consumer multicast source. Subject::new multicasts to the current subscribers, Subject::replay also replays the last n values (and the terminal state) to late subscribers.
  • Observable::subscribe / Observable::subscribe_all — push-based consumption through RxJS-style callbacks. Subscription is the cancellation handle and a Future: sub.await joins the subscription, the shape JoinHandle uses, while keeping the handle and unsubscribeing it is how a caller stops a stream early.
  • from, of, throw_error — channel-free local constructors; defer and from_future defer their work to the first poll, so a service call is only issued when someone consumes the stream.
  • ObservableInput — the bridge a projection uses to accept either an Observable or a Future that produces one, so an async fn client call composes without an explicit defer (RxJS ObservableInput).

§Operators

ReactiveX categoryOperators
Transformingmap, map_err, scan, switch_map
Filteringfilter, take, distinct_until_changed, skip, first, first_with
Combiningmerge, start_with
Conditional / Booleantake_until, take_until_token
Error handlingcatch_error, retry_with
Utilitytap, finalize, delay, timeout
Terminals (they end the chain)collect, first_value, last_value, for_each, subscribe, subscribe_all, next, recv

Two rules hold for every operator: it is pull-based and lazy (it only wraps its source in a boxed stream — no intermediate channel, no spawned task), and it never drops or reorders a terminal event unless its own documentation says otherwise. Only map_err and catch_error act on the business error; a technical RpcError is fatal and travels untouched.

§Normalization

A source may carry a single response as an internal single-sample optimization. Observable::recv normalizes it into Next followed by Complete, so consuming code always observes a uniform stream of Next values followed by a terminal event (Complete or Error).

§Timeouts

Observable::timeout is a per-event silence watchdog on an active stream, reset after every event.

Re-exports§

pub use rt::CancellationToken;

Modules§

rt
Execution facade: one full mode per host runtime, and a fallback for a deployment that has none.

Structs§

Observable
Consumer-side receiver of RPC events.
RetryPolicy
Policy of retry_with.
Sender
Producer-side sender of stream events.
Subject
A multi-producer / multi-consumer multicast source.
Subscription
Handle of a running subscription.

Enums§

Event
Event emitted by a stream, as observed by consumers.
ObservableError
The single error type of the whole streaming API.
RpcError
Technical RPC error, categorized so callers can choose a policy (retry / fallback / log / fatal) via RpcError::is_retryable.

Traits§

ObservableInput
Anything a combinator can accept as a source: an Observable itself, or a Future that produces one.

Functions§

channel
Creates a bounded channel of RPC events.
defer
Creates an observable from a deferred factory (RxJS defer).
from
Creates an observable from an iterator, emitting each value as Next then Complete.
from_future
Creates a one-value observable from a future (RxJS from(promise)).
of
Creates a single-value observable.
retry_with
Runs factory again on every failure, up to the policy’s attempts (RxJS retry).
throw_error
Creates an observable that only emits a business error.
unbounded_channel
Creates an unbounded channel of RPC events.