fluxus_utils/
models.rs

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