use thiserror::Error;
use crate::time::current_time;
#[derive(Debug, Clone)]
pub struct Record<T> {
pub data: T,
pub timestamp: i64,
}
impl<T> Record<T> {
pub fn new(data: T) -> Self {
let timestamp = current_time() as i64;
Record { data, timestamp }
}
pub fn with_timestamp(data: T, timestamp: i64) -> Self {
Record { data, timestamp }
}
}
#[derive(Error, Debug)]
pub enum StreamError {
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
#[error("Serialization error: {0}")]
Serialization(String),
#[error("Configuration error: {0}")]
Config(String),
#[error("Runtime error: {0}")]
Runtime(String),
#[error("EOF")]
EOF,
#[error("Wait for {0} milliseconds")]
Wait(u64),
}
pub type StreamResult<T> = Result<T, StreamError>;