nautilus_backtest/ffi/
engine.rs1use std::ops::{Deref, DerefMut};
17
18use nautilus_common::ffi::{clock::TestClock_API, timer::TimeEventHandler};
19use nautilus_core::{
20 UnixNanos,
21 ffi::{cvec::CVec, parsing::u8_as_bool},
22};
23
24use crate::engine::TimeEventAccumulator;
25
26#[repr(C)]
27pub struct TimeEventAccumulatorAPI(Box<TimeEventAccumulator>);
28
29impl Deref for TimeEventAccumulatorAPI {
30 type Target = TimeEventAccumulator;
31
32 fn deref(&self) -> &Self::Target {
33 &self.0
34 }
35}
36
37impl DerefMut for TimeEventAccumulatorAPI {
38 fn deref_mut(&mut self) -> &mut Self::Target {
39 &mut self.0
40 }
41}
42
43#[unsafe(no_mangle)]
44pub extern "C" fn time_event_accumulator_new() -> TimeEventAccumulatorAPI {
45 TimeEventAccumulatorAPI(Box::new(TimeEventAccumulator::new()))
46}
47
48#[unsafe(no_mangle)]
49pub extern "C" fn time_event_accumulator_drop(accumulator: TimeEventAccumulatorAPI) {
50 drop(accumulator); }
52
53#[unsafe(no_mangle)]
54pub extern "C" fn time_event_accumulator_advance_clock(
55 accumulator: &mut TimeEventAccumulatorAPI,
56 clock: &mut TestClock_API,
57 to_time_ns: UnixNanos,
58 set_time: u8,
59) {
60 accumulator.advance_clock(clock, to_time_ns, u8_as_bool(set_time));
61}
62
63#[unsafe(no_mangle)]
64pub extern "C" fn time_event_accumulator_drain(accumulator: &mut TimeEventAccumulatorAPI) -> CVec {
65 let handlers: Vec<TimeEventHandler> = accumulator.drain().into_iter().map(Into::into).collect();
66 handlers.into()
67}