pub mod data; mod guard; pub mod layer; pub mod state; pub mod util; use std::sync::Arc; pub use data::Data; use guard::Guard; pub use layer::{Layer, Value}; pub use state::State; pub use util::*; use crate::SyncMutex; pub type Filter = dyn Fn(Data<'_>) -> bool + Send + Sync + 'static; pub type Closure = dyn FnMut(Data<'_>) + Send + Sync + 'static; /// Capture instance state. pub struct Capture { state: Arc, filter: Option>, closure: SyncMutex>, } impl Capture { /// Construct a new capture instance. Capture does not start until the Guard /// is in scope. #[must_use] pub fn new(state: &Arc, filter: Option, closure: C) -> Arc where F: Fn(Data<'_>) -> bool + Send + Sync + 'static, C: FnMut(Data<'_>) + Send + Sync + 'static, { Arc::new(Self { state: state.clone(), filter: filter.map(|p| -> Box { Box::new(p) }), closure: SyncMutex::new(Box::new(closure)), }) } #[must_use] pub fn start(self: &Arc) -> Guard { self.state.add(self); Guard { capture: self.clone() } } pub fn stop(self: &Arc) { self.state.del(self); } }