1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
pub mod body;
pub mod header;

use crate::connector::counter::curl::body::Body;
use crate::connector::counter::curl::header::Header;
use crate::connector::curl::Curl;
use serde::{Deserialize, Serialize};
use std::io::Result;

#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(tag = "type")]
pub enum CounterType {
    #[serde(alias = "header")]
    Header(Header),
    #[serde(rename = "body")]
    Body(Body),
}

impl Default for CounterType {
    fn default() -> Self {
        CounterType::Header(Header::default())
    }
}

impl CounterType {
    pub async fn count(&self, connector: &Curl) -> Result<Option<usize>> {
        match self {
            CounterType::Header(header_counter) => header_counter.count(connector).await,
            CounterType::Body(body_counter) => body_counter.count(connector).await,
        }
    }
}