tuwunel_core/log/capture/
state.rs1use std::sync::{Arc, RwLock};
7
8use super::Capture;
9
10pub struct State {
12 pub(super) active: RwLock<Vec<Arc<Capture>>>,
13}
14
15impl Default for State {
16 fn default() -> Self { Self::new() }
17}
18
19impl State {
20 #[must_use]
25 pub fn new() -> Self { Self { active: RwLock::new(Vec::new()) } }
26
27 pub(super) fn add(&self, capture: &Arc<Capture>) {
28 self.active
29 .write()
30 .expect("locked for writing")
31 .push(capture.clone());
32 }
33
34 pub(super) fn del(&self, capture: &Arc<Capture>) {
35 let mut vec = self.active.write().expect("locked for writing");
36 if let Some(pos) = vec.iter().position(|v| Arc::ptr_eq(v, capture)) {
37 vec.swap_remove(pos);
38 }
39 }
40}