pub struct ErasedHandler { /* private fields */ }Expand description
Shared, type-erased handler. Clones retain the same handler allocation.
Implements Send + Sync on native targets, but not on WASM.
Implementations§
Source§impl ErasedHandler
impl ErasedHandler
A handler that serves nothing: it is descriptor, and every effect
it gets is answered ErrorKind::HandlerUnavailable with why. For
a model whose calls a plugin answers itself, such as from a batch,
so a call that reaches the handler by mistake fails plainly while
records still name the model.
use rig_core::completion::ModelRef;
use rig_core::effect::{FamilyDescriptor, HandlerDescriptor, model_key};
use rig_core::serve::ErasedHandler;
let descriptor = HandlerDescriptor {
key: model_key("batch/claude"),
family: FamilyDescriptor::Completion {
model: ModelRef::from("batch/claude"),
capabilities: Default::default(),
},
layers: Vec::new(),
};
let handler = ErasedHandler::unavailable(descriptor, "answered from the batch API");
assert_eq!(handler.key(), &model_key("batch/claude"));Sourcepub fn layered(self, intercept: impl Intercept) -> Self
pub fn layered(self, intercept: impl Intercept) -> Self
Wrap this handler in a Layer: intercept sees
every dispatch before this handler does and every answer after.
handler.layered(a).layered(b) calls b.before first and a.after first.
Sourcepub fn map_stream<M, F>(self, name: impl Into<String>, make: M) -> Selfwhere
M: Fn(Arc<PublishedContext>) -> F + WasmCompatSend + WasmCompatSync + 'static,
F: FnMut(Relayed) -> Vec<Relayed> + WasmCompatSend + 'static,
pub fn map_stream<M, F>(self, name: impl Into<String>, make: M) -> Selfwhere
M: Fn(Arc<PublishedContext>) -> F + WasmCompatSend + WasmCompatSync + 'static,
F: FnMut(Relayed) -> Vec<Relayed> + WasmCompatSend + 'static,
Rewrite this handler’s completion streams: every item of each reply
passes through a fresh make(published) in order, and the items it
returns go on in its place. It sees the Relayed::Done
too, so a rewrite of the events also rewrites the response the reply
ends with. A unary completion is rewritten as its events, so both
delivery modes answer alike; other outcomes and errors pass as they
are. name joins the descriptor’s layers.
published is the dispatch’s
PublishedContext: a fact the
rewrite inserts there before it passes the Done on, such as that
it split reasoning out of this reply, comes back to the driver beside
the reply and is recorded with it.
Unlike a Layer, the rewrite is recorded: the
record of a dispatch is the reply the consumer receives, so a replay
of it does not rewrite twice.
Sourcepub fn descriptor(&self) -> HandlerDescriptor
pub fn descriptor(&self) -> HandlerDescriptor
What the erased handler is.
Sourcepub fn key(&self) -> &HandlerKey
pub fn key(&self) -> &HandlerKey
The key of its descriptor, without building one.
Sourcepub fn handle(&self, kind: EffectKind, dispatch: Dispatch) -> HandlerFuture<'_>
pub fn handle(&self, kind: EffectKind, dispatch: Dispatch) -> HandlerFuture<'_>
Serve one effect: the driver’s call, straight to the boxed handler.
Sourcepub fn footprint(&self, kind: &EffectKind) -> Option<Touches>
pub fn footprint(&self, kind: &EffectKind) -> Option<Touches>
What dispatching kind to this handler may read and change
(Serve::footprint).
Sourcepub fn check(&self, kind: &EffectKind) -> Vec<UnsupportedOption>
pub fn check(&self, kind: &EffectKind) -> Vec<UnsupportedOption>
The options of kind this handler would leave out (Serve::check).
Trait Implementations§
Source§impl Clone for ErasedHandler
impl Clone for ErasedHandler
Source§impl Debug for ErasedHandler
impl Debug for ErasedHandler
Source§impl Serve for ErasedHandler
Forwards serving to the wrapped handler; re-erasure adds another boxed future.
impl Serve for ErasedHandler
Forwards serving to the wrapped handler; re-erasure adds another boxed future.
Source§fn descriptor(&self) -> HandlerDescriptor
fn descriptor(&self) -> HandlerDescriptor
Source§async fn serve(&self, kind: EffectKind, dispatch: Dispatch) -> Reply
async fn serve(&self, kind: EffectKind, dispatch: Dispatch) -> Reply
Source§fn footprint(&self, kind: &EffectKind) -> Option<Touches>
fn footprint(&self, kind: &EffectKind) -> Option<Touches>
kind may read and change, for a tool’s handler
(Tool::footprint); None when it
cannot say, such as for arguments that do not parse.Source§fn check(&self, kind: &EffectKind) -> Vec<UnsupportedOption>
fn check(&self, kind: &EffectKind) -> Vec<UnsupportedOption>
kind this handler would leave out when it serves
it, with nothing sent: for a model’s handler, what its wire or model
cannot honour (DynModel::check).
Empty when it leaves nothing out or cannot say, as by default.Source§fn key(&self) -> HandlerKey
fn key(&self) -> HandlerKey
Auto Trait Implementations§
impl !RefUnwindSafe for ErasedHandler
impl !UnwindSafe for ErasedHandler
impl Freeze for ErasedHandler
impl Send for ErasedHandler
impl Sync for ErasedHandler
impl Unpin for ErasedHandler
impl UnsafeUnpin for ErasedHandler
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more