tcplane/server/response/
impl.rs

1use super::error::Error;
2use crate::*;
3use std::io::Write;
4
5impl Default for Response {
6    #[inline]
7    fn default() -> Self {
8        Self { data: Vec::new() }
9    }
10}
11
12impl Response {
13    #[inline]
14    pub fn send(&mut self, mut stream: &TcpStream) -> ResponseResult {
15        let send_res: ResponseResult = stream
16            .write_all(&self.get_data())
17            .and_then(|_| stream.flush())
18            .map_err(|err| Error::ResponseError(err.to_string()))
19            .and_then(|_| Ok(self.get_data()))
20            .cloned();
21        send_res
22    }
23
24    #[inline]
25    pub fn set_data<T: Into<ResponseData>>(&mut self, data: T) -> &mut Self {
26        self.data = data.into();
27        self
28    }
29}