sonic-channel/src/commands/ping.rs
Dmitriy Pleshevskiy bd08317388
Design improvements ()
* protocol: extract response type

* deps: drop lazy_static and regex

* protocol: extract request commands

* protocol: create a struct for...

   ...formatting and parsing sonic protocol

* protocol: refac flush command

* commands: introduce dest, refac push and count

* commands: refac all commands

* commands: add convinient methods

* doc: add documentation for each new structs

* doc: change examples in the readme

* commands: implement from trait for count and flush

* commands: change pag logic
2022-07-18 11:07:12 +00:00

22 lines
478 B
Rust

use super::StreamCommand;
use crate::protocol;
use crate::result::*;
#[derive(Debug)]
pub struct PingCommand;
impl StreamCommand for PingCommand {
type Response = ();
fn request(&self) -> protocol::Request {
protocol::Request::Ping
}
fn receive(&self, res: protocol::Response) -> Result<Self::Response> {
if matches!(res, protocol::Response::Pong) {
Ok(())
} else {
Err(Error::WrongResponse)
}
}
}