safer_ring/advanced/
multi_shot.rs1#[derive(Debug, Clone, Default)]
9pub struct MultiShotConfig {
10 pub max_completions: Option<u32>,
12 pub continue_on_error: bool,
14 pub buffer_group_id: Option<u16>,
16}
17
18impl MultiShotConfig {
19 pub fn new() -> Self {
31 Self::default()
32 }
33
34 pub fn with_max_completions(mut self, max: u32) -> Self {
36 self.max_completions = Some(max);
37 self
38 }
39
40 pub fn with_continue_on_error(mut self) -> Self {
42 self.continue_on_error = true;
43 self
44 }
45
46 pub fn with_buffer_group(mut self, group_id: u16) -> Self {
48 self.buffer_group_id = Some(group_id);
49 self
50 }
51}
52
53#[cfg(test)]
54mod tests {
55 use super::*;
56
57 #[test]
58 fn test_default_config() {
59 let config = MultiShotConfig::default();
60
61 assert!(config.max_completions.is_none());
62 assert!(!config.continue_on_error);
63 assert!(config.buffer_group_id.is_none());
64 }
65
66 #[test]
67 fn test_builder_pattern() {
68 let config = MultiShotConfig::new()
69 .with_max_completions(50)
70 .with_continue_on_error()
71 .with_buffer_group(2);
72
73 assert_eq!(config.max_completions, Some(50));
74 assert!(config.continue_on_error);
75 assert_eq!(config.buffer_group_id, Some(2));
76 }
77}