use super::{IndicatorConfig, IndicatorResult};
use crate::core::OHLCV;
pub trait IndicatorInstance: Sized {
type Config: IndicatorConfig<Instance = Self>;
fn config(&self) -> &Self::Config;
fn next<T: OHLCV>(&mut self, candle: &T) -> IndicatorResult;
#[inline]
fn over<T, S>(&mut self, inputs: S) -> Vec<IndicatorResult>
where
T: OHLCV,
S: AsRef<[T]>,
{
let inputs_ref = inputs.as_ref();
inputs_ref.iter().map(|x| self.next(x)).collect()
}
fn size(&self) -> (u8, u8) {
self.config().size()
}
fn name(&self) -> &'static str {
Self::Config::NAME
}
fn into_fn<'a, T>(mut self) -> Box<dyn FnMut(&'a T) -> IndicatorResult>
where
T: OHLCV,
Self: 'static,
{
let f = move |x| self.next(x);
Box::new(f)
}
}