use std::fmt;
use std::sync::Arc;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Direction {
Sent,
Received,
Stderr,
}
pub trait Observer: Send + Sync {
fn record(&self, source: &'static str, direction: Direction, bytes: &[u8]);
}
impl<F> Observer for F
where
F: Fn(&'static str, Direction, &[u8]) + Send + Sync,
{
fn record(&self, source: &'static str, direction: Direction, bytes: &[u8]) {
self(source, direction, bytes)
}
}
pub type SharedObserver = Option<Arc<dyn Observer>>;
pub fn none() -> SharedObserver {
None
}
impl fmt::Debug for dyn Observer {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str("Observer(..)")
}
}