Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move IO responsibility out of Processor trait #134

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
5 changes: 2 additions & 3 deletions hftbacktest-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,6 @@ pub fn build_asset(input: TokenStream) -> TokenStream {
}

let local: Box<dyn LocalProcessor<#marketdepth>> = Box::new(#local_ident::new(
reader.clone(),
market_depth,
State::new(asset_type.clone(), fee_model.clone()),
latency_model.clone(),
Expand All @@ -318,7 +317,6 @@ pub fn build_asset(input: TokenStream) -> TokenStream {
let queue_model = #qm_construct;

let exch: Box<dyn Processor> = Box::new(#exch_ident::new(
reader,
market_depth,
State::new(asset_type, fee_model.clone()),
latency_model,
Expand All @@ -329,7 +327,8 @@ pub fn build_asset(input: TokenStream) -> TokenStream {

Asset {
local,
exch
exch,
reader
}
},
});
Expand Down
13 changes: 13 additions & 0 deletions hftbacktest/src/backtest/data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,19 @@ where
}
}

pub fn from_data(data: &[D]) -> Self {
let byte_len = size_of::<D>() * data.len();
let bytes = unsafe { std::slice::from_raw_parts(data.as_ptr() as *const u8, byte_len) };

unsafe {
let mut dest_data_ptr = DataPtr::new(byte_len);
let mut dest_data = dest_data_ptr.ptr.as_mut().expect("data ptr is null");

dest_data.copy_from_slice(bytes);
Self::from_data_ptr(dest_data_ptr, 0)
}
}

/// Constructs `Data` from [`DataPtr`] with the specified offset.
///
/// # Safety
Expand Down
Loading