pub struct NdjsonWriter { /* private fields */ }Expand description
Channel-based async NDJSON writer that decouples the hot path from disk I/O.
Broadcast sites call write_record() which serializes to Vec<u8> and does
a non-blocking mpsc::send() — no lock, no disk I/O on the hot path.
A dedicated tokio task owns the BufWriter and flushes on a timer.
Implementations§
Source§impl NdjsonWriter
impl NdjsonWriter
Sourcepub fn new<W: Write + Send + 'static>(writer: W) -> Self
pub fn new<W: Write + Send + 'static>(writer: W) -> Self
Spawn a dedicated writer task that owns writer exclusively.
Accepts W: Write + Send + 'static so callers can pass File,
BufWriter<File>, or a future rotation-aware writer without changing
any broadcast site code.
Sourcepub fn write_record<T: Serialize>(&self, msg: &T)
pub fn write_record<T: Serialize>(&self, msg: &T)
Serialize msg to NDJSON and enqueue for writing. Non-blocking.
If the writer task has died (channel closed), the record is silently dropped.
Auto Trait Implementations§
impl Freeze for NdjsonWriter
impl RefUnwindSafe for NdjsonWriter
impl Send for NdjsonWriter
impl Sync for NdjsonWriter
impl Unpin for NdjsonWriter
impl UnsafeUnpin for NdjsonWriter
impl UnwindSafe for NdjsonWriter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more