1use std::time::{SystemTime, UNIX_EPOCH};
2use thiserror::Error;
3
4#[derive(Debug)]
6pub struct Record<T> {
7 pub data: T,
9 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 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 pub fn with_timestamp(data: T, timestamp: i64) -> Self {
34 Record { data, timestamp }
35 }
36}
37
38#[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
54pub type StreamResult<T> = Result<T, StreamError>;