time/
request.rs

1//! # Request
2//!
3//! To control the timer, a client sends requests to the server and
4//! receive back a response. This module contains the request
5//! structure as well as trait to read and write a request.
6
7use async_trait::async_trait;
8use std::io::Result;
9
10/// The client request struct.
11///
12/// Requests are sent by clients and received by servers.
13#[derive(Clone, Debug, Eq, PartialEq)]
14pub enum Request {
15    /// Request the timer to start with the first configured cycle.
16    Start,
17
18    /// Request the state, the cycle and the value of the timer.
19    Get,
20
21    /// Request to change the current timer duration.
22    Set(usize),
23
24    /// Request to pause the timer.
25    ///
26    /// A paused timer freezes, which means it keeps its state, cycle
27    /// and value till it get resumed.
28    Pause,
29
30    /// Request to resume the paused timer.
31    ///
32    /// Has no effect if the timer is not paused.
33    Resume,
34
35    /// Request to stop the timer.
36    ///
37    /// Stopping the timer resets the state, the cycle and the value.
38    Stop,
39}
40
41/// Trait to read a client request.
42///
43/// Describes how a request should be parsed by a server.
44#[async_trait]
45pub trait RequestReader: Send + Sync {
46    /// Read the current client request.
47    async fn read(&mut self) -> Result<Request>;
48}
49
50/// Trait to write a client request.
51///
52/// Describes how a request should be sent by a client.
53#[async_trait]
54pub trait RequestWriter: Send + Sync {
55    /// Write the given client request.
56    async fn write(&mut self, req: Request) -> Result<()>;
57}