1pub mod buffered;
2pub mod console;
3pub mod dummy_sink;
4pub mod file;
5
6pub use buffered::BufferedSink;
7pub use console::ConsoleSink;
8pub use file::FileSink;
9
10use async_trait::async_trait;
11use fluxus_utils::models::{Record, StreamResult};
12use std::fmt::Display;
13
14#[async_trait]
16pub trait Sink<T> {
17 async fn init(&mut self) -> StreamResult<()>;
19
20 async fn write(&mut self, record: Record<T>) -> StreamResult<()>;
22
23 async fn flush(&mut self) -> StreamResult<()>;
25
26 async fn close(&mut self) -> StreamResult<()>;
28}
29
30pub trait ConsoleFormatter<T> {
32 fn format(&self, record: &Record<T>) -> String;
33}
34
35pub struct DefaultFormatter;
37
38impl<T: Display> ConsoleFormatter<T> for DefaultFormatter {
39 fn format(&self, record: &Record<T>) -> String {
40 format!("[{}] {}", record.timestamp, record.data)
41 }
42}