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
33
34
35
36
37
38
#![deny(warnings, rust_2018_idioms)]

mod distribution;
pub mod latency;
pub mod limit;

pub use self::{
    distribution::Distribution,
    latency::{parse_duration, InvalidDuration, Latency},
};
use bytes::Bytes;
use std::time::Duration;

#[async_trait::async_trait]
pub trait MakeOrt<T>: Clone + Send + 'static {
    type Ort: Ort;
    async fn make_ort(&mut self, target: T) -> Result<Self::Ort, Error>;
}

#[async_trait::async_trait]
pub trait Ort: Clone + Send + 'static {
    async fn ort(&mut self, spec: Spec) -> Result<Reply, Error>;
}

pub type Error = Box<dyn std::error::Error + Send + Sync + 'static>;

#[derive(Copy, Clone, Debug, Default, PartialEq)]
#[cfg_attr(feature = "deser", derive(serde::Serialize, serde::Deserialize))]
pub struct Spec {
    pub latency: Duration,
    pub response_size: usize,
}

#[derive(Clone, Debug, Default, PartialEq)]
#[cfg_attr(feature = "deser", derive(serde::Serialize, serde::Deserialize))]
pub struct Reply {
    pub data: Bytes,
}