pub struct Dispatcher { /* private fields */ }Expand description
Routes methods to a server’s handlers.
Implementations§
Source§impl Dispatcher
impl Dispatcher
Sourcepub fn state(&self) -> &Arc<StateMap> ⓘ
pub fn state(&self) -> &Arc<StateMap> ⓘ
The server’s state map, for a transport handler that needs to
hand it to a RequestContext.
Cloning the Arc is one bump; the contents of the map are not
touched on the read path.
Sourcepub fn handshake(
&self,
ctx: &RequestContext,
params: &JsonObject,
) -> Result<(JsonObject, PeerSession), DispatchError>
pub fn handshake( &self, ctx: &RequestContext, params: &JsonObject, ) -> Result<(JsonObject, PeerSession), DispatchError>
Runs the handshake and returns the session narrowed to what was negotiated.
dispatch answers initialize and discards the
negotiated profile, which leaves the caller gating the rest of the
connection on the profile the session was constructed with — a
revision chosen before the peer existed. That is the right answer only
when the peer happens to want the newest revision this build serves.
The returned session is what the transport must carry forward: it holds the profile resolved for the revision the client actually asked for, so every later gate reads that. Transport-specific policy still belongs to the transport; the profile does not belong to the caller.
§Errors
As dispatch for initialize, and
DispatchError::MalformedInitialize when the body does not carry a
readable version and capability block.
Sourcepub async fn dispatch(
&self,
ctx: &RequestContext,
method: &str,
params: &JsonObject,
) -> Result<JsonObject, DispatchError>
pub async fn dispatch( &self, ctx: &RequestContext, method: &str, params: &JsonObject, ) -> Result<JsonObject, DispatchError>
Routes one request.
The gate runs before anything is read out of params, so a method the
session cannot use does not even parse its arguments — the same order
RequestContext’s own gated calls use, and for the same reason.
§Errors
DispatchError::UnknownMethod for a name no method answers, and
DispatchError::NotCallable for a method whose feature the session
does not have. Both are refusals that wrote nothing.