haproxy_stats_socket/client/
impl_show_stat.rs

1use core::fmt;
2
3use haproxy_stats::{stat::StatisticsFromCsvBytesError, Command, Statistic, Statistics};
4
5use super::{Client, ClientSendError};
6
7//
8impl Client {
9    pub async fn show_stat(&self) -> Result<Vec<Statistic>, ClientShowStatError> {
10        let response = self
11            .send_async(&Command::show_stat())
12            .await
13            .map_err(ClientShowStatError::ClientSendError)?;
14
15        let statistics = Statistics::from_csv_bytes(response)
16            .map_err(ClientShowStatError::ResponseParseError)?;
17
18        Ok(statistics.0)
19    }
20}
21
22//
23#[derive(Debug)]
24pub enum ClientShowStatError {
25    ClientSendError(ClientSendError),
26    ResponseParseError(StatisticsFromCsvBytesError),
27}
28
29impl fmt::Display for ClientShowStatError {
30    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31        write!(f, "{:?}", self)
32    }
33}
34
35impl std::error::Error for ClientShowStatError {}