use crate::store::TrackStore;
use crate::track::notify::{ChangeNotifier, NoopNotifier};
use crate::track::{ObservationAttributes, ObservationMetric, TrackAttributes};
use std::marker::PhantomData;
pub struct TrackStoreBuilder<TA, M, OA, N = NoopNotifier>
where
TA: TrackAttributes<TA, OA>,
M: ObservationMetric<TA, OA>,
OA: ObservationAttributes,
N: ChangeNotifier,
{
metric: Option<M>,
default_attributes: Option<TA>,
notifier: Option<N>,
shards: usize,
_phantom_oa: PhantomData<OA>,
}
impl<TA, M, OA, N> Default for TrackStoreBuilder<TA, M, OA, N>
where
TA: TrackAttributes<TA, OA>,
M: ObservationMetric<TA, OA>,
OA: ObservationAttributes,
N: ChangeNotifier,
{
fn default() -> TrackStoreBuilder<TA, M, OA, N> {
Self::new(num_cpus::get())
}
}
impl<TA, M, OA, N> TrackStoreBuilder<TA, M, OA, N>
where
TA: TrackAttributes<TA, OA>,
M: ObservationMetric<TA, OA>,
OA: ObservationAttributes,
N: ChangeNotifier,
{
pub fn new(shards: usize) -> Self {
TrackStoreBuilder {
shards,
metric: None,
default_attributes: None,
notifier: None,
_phantom_oa: PhantomData,
}
}
pub fn metric(mut self, metric: M) -> Self {
assert!(
self.metric.is_none(),
"The method `metric` must be called once."
);
self.metric = Some(metric);
self
}
pub fn notifier(mut self, notifier: N) -> Self {
assert!(
self.notifier.is_none(),
"The method `notifier` must be called once."
);
self.notifier = Some(notifier);
self
}
pub fn default_attributes(mut self, attrs: TA) -> Self {
assert!(
self.default_attributes.is_none(),
"The method `default_attributes` must be called once."
);
self.default_attributes = Some(attrs);
self
}
pub fn build(self) -> TrackStore<TA, M, OA, N> {
TrackStore::new(
self.metric.unwrap(),
self.default_attributes.unwrap(),
self.notifier.unwrap(),
self.shards,
)
}
}