tcp_lib/write/
state.rs

1/// The TCP I/O state, owned by flows and updated by handlers.
2///
3/// This struct represents the I/O state used by I/O handlers to take
4/// input and set output. It is usually owned by flows themselves, and
5/// serve as communication bridge between flows and I/O handlers.
6#[derive(Debug)]
7pub struct State {
8    pub(crate) buffer: Vec<u8>,
9    pub(crate) bytes_count: Option<usize>,
10}
11
12/// State constructors.
13///
14/// This implementation gathers functions for building new states.
15impl State {
16    /// Builds a new state using the given reading capacity.
17    ///
18    /// See [`State::new`] for building a state with a default reading
19    /// capacity.
20    pub(crate) fn new(bytes: Vec<u8>) -> Self {
21        Self {
22            buffer: bytes,
23            bytes_count: None,
24        }
25    }
26
27    pub fn get_buffer(&self) -> &[u8] {
28        &self.buffer
29    }
30
31    pub fn set_bytes_count(&mut self, bytes_count: usize) {
32        self.bytes_count.replace(bytes_count);
33    }
34}