fluxus_utils/
models.rs

1use thiserror::Error;
2
3use crate::time::current_time;
4
5/// Record represents a single data record in the stream
6#[derive(Debug, Clone)]
7pub struct Record<T> {
8    /// The actual data payload
9    pub data: T,
10    /// Timestamp of the record (in milliseconds)
11    pub timestamp: i64,
12}
13
14impl<T> Record<T> {
15    /// Create a new record with the current timestamp
16    pub fn new(data: T) -> Self {
17        let timestamp = current_time() as i64;
18        Record { data, timestamp }
19    }
20
21    /// Create a new record with a specific timestamp
22    pub fn with_timestamp(data: T, timestamp: i64) -> Self {
23        Record { data, timestamp }
24    }
25}
26
27/// Error types that can occur during stream processing
28#[derive(Error, Debug)]
29pub enum StreamError {
30    #[error("IO error: {0}")]
31    Io(#[from] std::io::Error),
32
33    #[error("Serialization error: {0}")]
34    Serialization(String),
35
36    #[error("Configuration error: {0}")]
37    Config(String),
38
39    #[error("Runtime error: {0}")]
40    Runtime(String),
41
42    #[error("EOF")]
43    EOF,
44
45    #[error("Wait for {0} milliseconds")]
46    Wait(u64),
47}
48
49/// A Result type specialized for stream processing operations
50pub type StreamResult<T> = Result<T, StreamError>;