time/response.rs
1//! # Response
2//!
3//! When a server receives a request, it sends back a response. This
4//! module contains the response structure as well as traits to read
5//! and write a response.
6
7use async_trait::async_trait;
8use std::io::Result;
9
10use crate::timer::Timer;
11
12/// The server response struct.
13///
14/// Responses are sent by servers and received by clients.
15#[derive(Clone, Debug, Eq, PartialEq)]
16pub enum Response {
17 /// Default response when everything goes as expected.
18 Ok,
19
20 /// Response containing the current timer.
21 Timer(Timer),
22}
23
24/// Trait to read a server response.
25///
26/// Describes how a response should be parsed by a client.
27#[async_trait]
28pub trait ResponseReader: Send + Sync {
29 /// Read the current server response.
30 async fn read(&mut self) -> Result<Response>;
31}
32
33/// Trait to write a response.
34///
35/// Describes how a response should be sent by a server.
36#[async_trait]
37pub trait ResponseWriter: Send + Sync {
38 /// Write the given response.
39 async fn write(&mut self, res: Response) -> Result<()>;
40}