use crate::{CompactOutput, OutputRange, Result};
pub(crate) mod sealed {
pub trait Sealed {}
}
pub trait IndicatorConfig: Sized + sealed::Sealed {
type Input<'a>
where
Self: 'a;
type Output;
type OutputMut<'a>
where
Self: 'a;
type BatchRunner: PreparedBatchRunner<Self>;
type Stream: StreamingComputation<Self>;
fn lookback(&self) -> usize;
fn compute<'a>(&self, input: Self::Input<'a>) -> Result<CompactOutput<Self::Output>>;
fn compute_into<'a>(
&self,
input: Self::Input<'a>,
output: Self::OutputMut<'a>,
) -> Result<OutputRange>;
fn prepare_batch(&self, max_input_len: usize) -> Result<Self::BatchRunner>;
fn stream(&self) -> Result<Self::Stream>;
}
pub trait PreparedBatchRunner<C: IndicatorConfig>: sealed::Sealed {
fn max_input_len(&self) -> usize;
fn compute_into<'a>(
&mut self,
input: C::Input<'a>,
output: C::OutputMut<'a>,
) -> Result<OutputRange>
where
C: 'a;
}
pub trait StreamingComputation<C: IndicatorConfig>: sealed::Sealed {
type Tick;
type TickOutput;
fn next(&mut self, input: Self::Tick) -> Result<Option<Self::TickOutput>>;
fn reset(&mut self);
}