time/
tcp.rs

1//! # TCP
2//!
3//! This module contains shared TCP code for both server and
4//! client.
5
6use serde::{Deserialize, Serialize};
7use tokio::{
8    io::{self, BufReader, ReadHalf, WriteHalf},
9    net::TcpStream,
10};
11
12/// The TCP stream handler struct.
13///
14/// Wrapper around a TCP stream reader and writer.
15pub struct TcpHandler {
16    /// The TCP stream reader.
17    pub reader: BufReader<ReadHalf<TcpStream>>,
18
19    /// The TCP stream writer.
20    pub writer: WriteHalf<TcpStream>,
21}
22
23impl From<TcpStream> for TcpHandler {
24    fn from(stream: TcpStream) -> Self {
25        let (reader, writer) = io::split(stream);
26        let reader = BufReader::new(reader);
27        Self { reader, writer }
28    }
29}
30
31/// The TCP shared configuration between clients and servers.
32#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
33pub struct TcpConfig {
34    /// The TCP host name.
35    pub host: String,
36
37    /// The TCP port.
38    pub port: u16,
39}