Skip to main content

haystack_server/
his_provider.rs

1//! Pluggable history storage backend.
2//!
3//! The default implementation is [`HisStore`](crate::his_store::HisStore) (in-memory).
4//! Implement this trait to back hisRead/hisWrite with a database.
5
6use std::future::Future;
7use std::pin::Pin;
8
9use chrono::{DateTime, FixedOffset};
10
11use crate::his_store::HisItem;
12
13/// Trait for history storage backends.
14pub trait HistoryProvider: Send + Sync + 'static {
15    /// Read historical items for an entity within the optional time range.
16    fn his_read(
17        &self,
18        id: &str,
19        start: Option<DateTime<FixedOffset>>,
20        end: Option<DateTime<FixedOffset>>,
21    ) -> Pin<Box<dyn Future<Output = Vec<HisItem>> + Send + '_>>;
22
23    /// Write historical items for an entity.
24    fn his_write(
25        &self,
26        id: &str,
27        items: Vec<HisItem>,
28    ) -> Pin<Box<dyn Future<Output = ()> + Send + '_>>;
29}