1use std::time::Duration;
3
4#[derive(Debug, Clone)]
6pub struct BackendConfig {
7 queue_depth: usize,
8 event_batch_size: usize,
9 spin_before_park: Duration,
10 default_timeout: Option<Duration>,
11}
12
13impl BackendConfig {
14 pub fn new() -> Self {
16 Self::default()
17 }
18
19 pub fn queue_depth(&self) -> usize {
21 self.queue_depth
22 }
23
24 pub fn event_batch_size(&self) -> usize {
26 self.event_batch_size
27 }
28
29 pub fn spin_before_park(&self) -> Duration {
31 self.spin_before_park
32 }
33
34 pub fn default_timeout(&self) -> Option<Duration> {
36 self.default_timeout
37 }
38
39 pub fn with_queue_depth(mut self, queue_depth: usize) -> Self {
41 self.queue_depth = queue_depth.max(1);
42 self
43 }
44
45 pub fn with_event_batch_size(mut self, batch: usize) -> Self {
47 self.event_batch_size = batch.max(1);
48 self
49 }
50
51 pub fn with_spin_before_park(mut self, duration: Duration) -> Self {
53 self.spin_before_park = duration;
54 self
55 }
56
57 pub fn with_default_timeout(mut self, timeout: Option<Duration>) -> Self {
59 self.default_timeout = timeout;
60 self
61 }
62}
63
64impl Default for BackendConfig {
65 fn default() -> Self {
66 Self {
67 queue_depth: 4096,
68 event_batch_size: 512,
69 spin_before_park: Duration::from_micros(50),
70 default_timeout: None,
71 }
72 }
73}