1use thiserror::Error;
2
3use crate::time::current_time;
4
5#[derive(Debug, Clone)]
7pub struct Record<T> {
8 pub data: T,
10 pub timestamp: i64,
12}
13
14impl<T> Record<T> {
15 pub fn new(data: T) -> Self {
17 let timestamp = current_time() as i64;
18 Record { data, timestamp }
19 }
20
21 pub fn with_timestamp(data: T, timestamp: i64) -> Self {
23 Record { data, timestamp }
24 }
25}
26
27#[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
49pub type StreamResult<T> = Result<T, StreamError>;