fluxus_sinks/
lib.rs

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/// Sink trait defines the interface for data output
15#[async_trait]
16pub trait Sink<T> {
17    /// Initialize the sink
18    async fn init(&mut self) -> StreamResult<()>;
19
20    /// Write a record to the sink
21    async fn write(&mut self, record: Record<T>) -> StreamResult<()>;
22
23    /// Flush any buffered data
24    async fn flush(&mut self) -> StreamResult<()>;
25
26    /// Close the sink and release resources
27    async fn close(&mut self) -> StreamResult<()>;
28}
29
30/// Formatter for console output
31pub trait ConsoleFormatter<T> {
32    fn format(&self, record: &Record<T>) -> String;
33}
34
35/// Default formatter that uses Display
36pub 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}