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
39
40
41
42
43
44
45
46
use crate::priv_prelude::*;
/// Extension trait for types which are both `Sink`s and `Stream`s.
pub trait SinkStreamExt<T>: Stream + Sink<T> {
/// Delays items sent/received through this `Sink`/`Stream`.
///
/// * `min_delay` is the minimum delay which is applied to all items.
/// * `mean_additional_delay` is the average randomized delay applied to all items in addition
/// to `min_delay`. Setting this to zero disables delay randomization and guarantees that
/// items are recieved in the order they're sent.
fn with_delay(
self,
min_delay: Duration,
mean_additional_delay: Duration,
) -> crate::adapter::Delay<Self, T>
where
Self: Sized,
{
crate::adapter::Delay::new(self, min_delay, mean_additional_delay)
}
/// Randomly drops items sent through this `Sink`/`Stream`.
///
/// * `loss_rate` is what proportion of the items to drop. Setting to `1.0` will drop
/// everything, setting to `0.0` will drop nothing.
/// * `jitter_period` controls the average rate of switching between dropping and not dropping
/// items. Setting this to zero disables jitter so that each item has an independent
/// probability of getting dropped.
fn with_loss(
self,
loss_rate: f64,
jitter_period: Duration,
) -> crate::adapter::Loss<Self>
where
Self: Sized,
{
crate::adapter::Loss::new(self, loss_rate, jitter_period)
}
}
impl<S, T> SinkStreamExt<T> for S
where
S: Stream + Sink<T>,
{
}