Sans IO dispatch

This commit is contained in:
Aleksey Kladov 2018-08-12 22:12:51 +03:00
parent 1962369806
commit b518fd0ef9
2 changed files with 4 additions and 11 deletions

View file

@ -10,7 +10,7 @@ use drop_bomb::DropBomb;
use ::{ use ::{
Result, Result,
req::{ClientRequest, Notification}, req::{ClientRequest, Notification},
io::{Io, RawMsg, RawResponse, RawRequest, RawNotification}, io::{RawResponse, RawRequest, RawNotification},
}; };
pub struct Responder<R: ClientRequest> { pub struct Responder<R: ClientRequest> {
@ -113,9 +113,9 @@ pub fn send_notification<N>(params: N::Params) -> RawNotification
} }
} }
pub fn unknown_method(id: u64) -> Result<RawResponse> {
error_response(id, ErrorCode::MethodNotFound, "unknown method")
pub fn unknown_method(io: &mut Io, raw: RawRequest) -> Result<()> {
error(io, raw.id, ErrorCode::MethodNotFound, "unknown method")
} }
fn error_response(id: u64, code: ErrorCode, message: &'static str) -> Result<RawResponse> { fn error_response(id: u64, code: ErrorCode, message: &'static str) -> Result<RawResponse> {
@ -135,13 +135,6 @@ fn error_response(id: u64, code: ErrorCode, message: &'static str) -> Result<Raw
Ok(resp) Ok(resp)
} }
fn error(io: &mut Io, id: u64, code: ErrorCode, message: &'static str) -> Result<()> {
let resp = error_response(id, code, message)?;
io.send(RawMsg::Response(resp));
Ok(())
}
#[allow(unused)] #[allow(unused)]
enum ErrorCode { enum ErrorCode {
ParseError = -32700, ParseError = -32700,

View file

@ -102,7 +102,7 @@ fn on_msg(
} }
if let Some(req) = req { if let Some(req) = req {
error!("unknown method: {:?}", req); error!("unknown method: {:?}", req);
dispatch::unknown_method(io, req)?; io.send(RawMsg::Response(dispatch::unknown_method(req.id)?));
} }
} }
RawMsg::Notification(not) => { RawMsg::Notification(not) => {