use std::io::{Read, Write}; use entry::Entry; pub mod entry; mod error; pub mod layer; pub mod processor; pub use error::Error; pub struct TraceWriter { writer: W, receiver: tokio::sync::mpsc::UnboundedReceiver, } pub struct Trace { receiver: tokio::sync::mpsc::UnboundedReceiver, } impl Trace { pub fn into_receiver(self) -> tokio::sync::mpsc::UnboundedReceiver { self.receiver } pub fn into_writer(self, writer: W) -> TraceWriter { TraceWriter { writer, receiver: self.receiver } } } pub struct TraceReader { reader: R, } impl TraceReader { pub fn new(reader: R) -> Self { Self { reader } } fn read(&mut self) -> Option> { serde_json::Deserializer::from_reader(&mut self.reader) .into_iter() .next() .map(|res| res.map_err(Into::into)) } } impl Iterator for TraceReader { type Item = Result; fn next(&mut self) -> Option { self.read() } }