Closed Igosuki closed 2 years ago
Hello. Thank you for you participation. Unfortunately, I don't think it's a good idea. It is better to keep traits restrictions as low as possible in the libraries.
IndicatorConfigDyn
and IndicatorInstanceDyn
in fact are just auto-traits. So you can create traits like this on your own:
trait IndicatorConfigSendDyn<T: OHLCV>: Send {
fn init(&self, initial_value: &T) -> Result<Box<dyn IndicatorConfigSendDyn<T>>, Error>;
... // other methods
}
impl<T, C, I> IndicatorConfigSendDyn<T> for C
where
T: OHLCV,
I: IndicatorInstanceSendDyn<T> + IndicatorInstance<Config = Self> + Send + 'static,
C: IndicatorConfig<Instance = I> + Clone + Send + 'static,
{
fn init(&self, initial_value: &T) -> Result<Box<dyn IndicatorInstanceSendDyn<T>>, Error> {
let instance = IndicatorConfig::init(self.clone(), initial_value)?;
Ok(Box::from(instance))
}
... // other methods
}
You're right, copy paste will be enough, thanks.
Hi, I'm using yata with pyo3 which requires boxed values to be Send. IndicatorInstance isn't Send so I can't send IndicatorInstanceDyn between threads unless I mark it with Send, since IndicatorConfigDyn::init returns IndicatorInstanceDyn which isn't Send, I figured I needed to add the trait explicitly.
If you have a better option or recommendation feel free to close the PR with comment.