Skip to main content

ResourceHandler

Type Alias ResourceHandler 

Source
pub type ResourceHandler = Arc<dyn Fn(RequestContext, String) -> BoxReadFuture + Send + Sync>;
Expand description

Serves one resources/read, given the URI the peer asked for.

Takes the URI rather than closing over it, because the URI is the request. A handler that closed over its own registration would have to be one per resource, and the point of the lookup table is that the dispatcher finds the right one from the request the peer actually sent.

Takes the URI by value rather than by reference. A reference would put a lifetime on the handler type, and a closure whose signature carries one cannot be inferred as higher-ranked — so the coercion to this type fails with a lifetime error aimed at the #[server] attribute. The dispatcher already owns the string it parsed out of the request, so this costs one clone and buys a handler type with no lifetimes in it at all.

Aliased Type§

pub struct ResourceHandler { /* private fields */ }