#![feature(exclusive_range_pattern)] pub mod windows; pub mod encoding; #[allow(unused)] #[cfg(test)] mod tests { use serde::Deserialize; #[derive(Debug, Deserialize)] struct Trade { pub time: i64, pub price: f64, pub amount: f64, } #[test] fn serde_deserialize_json_example() { assert!(matches!( serde_json::from_str::(r#"{"time":1527811201900505632,"price":7492.279785,"amount":0.048495,"exch":"bits","server_time":0,"side":null}"#), Ok(Trade { time: 1527811201900505632, price: 7492.279785, amount: 0.048495 }) )); } #[test] fn serde_deserialize_csv_example() { let csv = "time,amount,exch,price,server_time,side\n\ 1527811201900505632,0.048495,bits,7492.279785,0,"; let mut csv_reader = csv::Reader::from_reader(csv.as_bytes()); let headers = csv_reader .headers() .expect("parsing row headers failed") .clone(); let mut row = csv::StringRecord::new(); assert!(matches!( csv_reader.read_record(&mut row), Ok(true) )); assert!(matches!( row.deserialize(Some(&headers)), Ok(Trade { time: 1527811201900505632, price: 7492.279785, amount: 0.048495 }) )); assert!(matches!( csv_reader.read_record(&mut row), Ok(false) )); } #[test] fn memory_size_of_trades_struct() { // tests an example in one of the baselines articles showing how with // no particular effort this struct is 48 bytes, compared to the // CSV per-row representation of an average of 73 bytes use markets::crypto::{Exchange, Ticker, Side}; struct Trade { pub time: u64, pub price: f64, pub amount: f64, pub exch: Exchange, pub ticker: Ticker, pub server_time: Option, pub side: Option, } assert_eq!(std::mem::size_of::(), 48); assert_eq!(std::mem::size_of::(), 2); } }