Skip to main content

rig_core/serve/
mod.rs

1#![forbid(unsafe_code)]
2
3//! Handlers return a [`Reply`]: an outcome or an owned stream. [`Dispatch`]
4//! carries identity, requested delivery mode and scopes. [`ErasedHandler`]
5//! is the shared registry boundary; drivers own polling and cancellation.
6//! Provider and tool authors retain their domain traits through [`adapters`].
7//! [`Reply::written`] offers a writer that mints stream block identities.
8//!
9//! ```
10//! use rig_core::serve::ServingPolicy;
11//!
12//! let policy = ServingPolicy::default();
13//! assert!(!policy.serial_per_handler);
14//! ```
15
16pub mod adapters;
17mod handler;
18mod layer;
19mod recorder;
20mod writer;
21
22pub use handler::{
23    Dispatch, ErasedHandler, HandlerFuture, Observe, Reply, Resolver, Serve, SinkClosed, StreamTap,
24    cancelled, deferred, serve_inline, serve_inline_with, stream_truncated,
25};
26pub use layer::{Decision, Intercept, Layer, Verdict};
27pub use recorder::{Origin, Recorder};
28pub use writer::StreamWriter;
29
30/// Driver queue capacities and per-handler ordering policy, retained as data
31/// for recording and replay.
32#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
33pub struct ServingPolicy {
34    /// Commands the driver buffers, bus-wide, before a dispatch parks at
35    /// its send stage until the driver drains. The bound holds across every
36    /// dispatcher and every dispatch; the caller of a dispatch is never
37    /// blocked.
38    pub command_capacity: usize,
39    /// Driver delivery queue capacity. rig-agent bounds its consumer queue;
40    /// rig-ecs uses at least one shared slot plus one sender-reserved slot.
41    /// Source-internal buffers and collection work limits are separate.
42    pub stream_capacity: usize,
43    /// Serves one command at a time per key in arrival order when true;
44    /// otherwise permits concurrent execution.
45    ///
46    /// Serial handlers must not dispatch to their own key and await the result,
47    /// which would deadlock. Drivers reject detectable cases as request errors.
48    /// Use another key or concurrent serving for nested calls to the same handler.
49    pub serial_per_handler: bool,
50}
51
52impl Default for ServingPolicy {
53    fn default() -> Self {
54        Self {
55            command_capacity: 16,
56            stream_capacity: 64,
57            serial_per_handler: false,
58        }
59    }
60}