pub trait InputResolver: Send + Sync {
// Required method
fn resolve<'a>(
&'a self,
key: &'a str,
method: &'a str,
params: &'a JsonObject,
) -> Pin<Box<dyn Future<Output = Option<JsonObject>> + Send + 'a>>;
}Expand description
Answers one input request.
Given the request’s key, its method (elicitation/create,
sampling/createMessage or roots/list) and its params, returns the answer
— an ElicitResult, CreateMessageResult or ListRootsResult — or None
when it cannot. Any closure Fn(String, String, JsonObject) -> impl Future
is one, so most callers never name this trait.
A trait with a boxed future rather than an AsyncFn bound because an
AsyncFn’s future cannot be required to be Send on stable Rust, and a
call that cannot be moved onto a tokio::spawn is not usable by the
callers who need it most.
§Examples
use protocol_droid::application::client::inputs::InputResolver;
use protocol_droid::domain::ir::JsonObject;
fn takes(_: &impl InputResolver) {}
takes(&|_key: String, method: String, _params: JsonObject| async move {
(method == "roots/list").then(|| JsonObject::new(r#"{"roots":[]}"#).unwrap_or_default())
});Required Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".