use chrono::{DateTime, Utc};
use futures::Stream;
use serde::{Deserialize, Serialize};
pub trait DataStream<Args> {
type Item;
type Error;
fn init(
args: Args,
) -> impl Future<Output = Result<impl Stream<Item = Self::Item> + Send, Self::Error>> + Send;
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize)]
pub struct DataArgs<Mode, Subs, Config> {
pub mode: Mode,
pub subscriptions: Subs,
pub config: Config,
}
impl<Subs, Config> DataArgs<Live, Subs, Config> {
pub fn live(subscriptions: Subs, config: Config) -> Self {
Self {
mode: Live,
subscriptions,
config,
}
}
}
impl<Subs, Config> DataArgs<Historical, Subs, Config> {
pub fn historical(historical: Historical, subscriptions: Subs, config: Config) -> Self {
Self {
mode: historical,
subscriptions,
config,
}
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize)]
pub struct Live;
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize)]
pub struct Historical {
pub start: DateTime<Utc>,
pub end: Option<DateTime<Utc>>,
}
#[cfg(test)]
#[allow(clippy::unwrap_used)] mod tests {
use super::*;
#[test]
fn test_data_args_live() {
let args = DataArgs::live(vec!["sub1", "sub2"], "config");
assert_eq!(args.mode, Live);
assert_eq!(args.subscriptions, vec!["sub1", "sub2"]);
assert_eq!(args.config, "config");
}
#[test]
fn test_data_args_historical() {
let start = Utc::now();
let historical = Historical { start, end: None };
let args = DataArgs::historical(historical, vec!["sub"], "cfg");
assert_eq!(args.mode.start, start);
assert!(args.mode.end.is_none());
assert_eq!(args.subscriptions, vec!["sub"]);
}
}