Skip to content

Commit

Permalink
Fix clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdsellers committed Jan 5, 2024
1 parent 8aa655d commit 73b4729
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 26 deletions.
1 change: 1 addition & 0 deletions nautilus_core/adapters/src/databento/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use ustr::Ustr;

use super::types::DatabentoPublisher;

#[must_use]
pub fn nautilus_instrument_id_from_databento(
raw_symbol: Ustr,
publisher: &DatabentoPublisher,
Expand Down
8 changes: 7 additions & 1 deletion nautilus_core/adapters/src/databento/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const BAR_CLOSE_ADJUSTMENT_1M: u64 = NANOSECONDS_IN_SECOND * 60;
const BAR_CLOSE_ADJUSTMENT_1H: u64 = NANOSECONDS_IN_SECOND * 60 * 60;
const BAR_CLOSE_ADJUSTMENT_1D: u64 = NANOSECONDS_IN_SECOND * 60 * 60 * 24;

#[must_use]
pub fn parse_order_side(c: c_char) -> OrderSide {
match c as u8 as char {
'A' => OrderSide::Sell,
Expand All @@ -83,6 +84,7 @@ pub fn parse_order_side(c: c_char) -> OrderSide {
}
}

#[must_use]
pub fn parse_aggressor_side(c: c_char) -> AggressorSide {
match c as u8 as char {
'A' => AggressorSide::Seller,
Expand Down Expand Up @@ -144,7 +146,10 @@ pub fn parse_cfi_iso10926(value: &str) -> Result<(Option<AssetClass>, Option<Ins

pub fn parse_min_price_increment(value: i64, currency: Currency) -> Result<Price> {
match value {
0 | i64::MAX => Price::new(10f64.powi(-(currency.precision as i32)), currency.precision),
0 | i64::MAX => Price::new(
10f64.powi(-i32::from(currency.precision)),
currency.precision,
),
_ => Price::from_raw(value, currency.precision),
}
}
Expand Down Expand Up @@ -255,6 +260,7 @@ pub fn parse_options_contract(
)
}

#[must_use]
pub fn is_trade_msg(order_side: OrderSide, action: c_char) -> bool {
order_side == OrderSide::NoOrderSide || action as u8 as char == 'T'
}
Expand Down
2 changes: 1 addition & 1 deletion nautilus_core/core/src/correctness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ mod tests {
#[case] r: u64,
#[case] desc: &str,
) {
assert!(check_u64_in_range_inclusive(value, l, r, desc).is_err())
assert!(check_u64_in_range_inclusive(value, l, r, desc).is_err());
}

#[rstest]
Expand Down
8 changes: 4 additions & 4 deletions nautilus_core/core/src/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,10 @@ mod tests {
}

#[rstest]
#[case(2023, 12, 15, 1702598400000000000)] // Fri
#[case(2023, 12, 16, 1702598400000000000)] // Sat
#[case(2023, 12, 17, 1702598400000000000)] // Sun
#[case(2023, 12, 18, 1702857600000000000)] // Mon
#[case(2023, 12, 15, 1_702_598_400_000_000_000)] // Fri
#[case(2023, 12, 16, 1_702_598_400_000_000_000)] // Sat
#[case(2023, 12, 17, 1_702_598_400_000_000_000)] // Sun
#[case(2023, 12, 18, 1_702_857_600_000_000_000)] // Mon
fn test_last_closest_weekday_nanos_with_valid_date(
#[case] year: i32,
#[case] month: u32,
Expand Down
10 changes: 5 additions & 5 deletions nautilus_core/core/src/ffi/cvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ mod tests {
assert_eq!(len, vec_len);
assert_eq!(cap, vec_cap);

let data = ptr as *mut u64;
let data = ptr.cast::<u64>();
unsafe {
assert_eq!(*data, test_data[0]);
assert_eq!(*data.add(1), test_data[1]);
Expand All @@ -139,7 +139,7 @@ mod tests {

unsafe {
// reconstruct the struct and drop the memory to deallocate
let _ = Vec::from_raw_parts(ptr as *mut u64, len, cap);
let _ = Vec::from_raw_parts(ptr.cast::<u64>(), len, cap);
}
}

Expand All @@ -156,10 +156,10 @@ mod tests {
};

let CVec { ptr, len, cap } = cvec;
let data = ptr as *mut u64;
let data = ptr.cast::<u64>();

unsafe {
let data: Vec<u64> = Vec::from_raw_parts(ptr as *mut u64, len, cap);
let data: Vec<u64> = Vec::from_raw_parts(ptr.cast::<u64>(), len, cap);
drop(data);
}

Expand All @@ -175,6 +175,6 @@ mod tests {
fn empty_vec_should_give_null_ptr() {
let data: Vec<u64> = vec![];
let cvec: CVec = data.into();
assert_eq!(cvec.ptr as *mut u64, null() as *const u64 as *mut u64);
assert_eq!(cvec.ptr.cast::<u64>(), null::<u64>().cast_mut());
}
}
10 changes: 5 additions & 5 deletions nautilus_core/core/src/ffi/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ mod tests {
#[rstest]
fn test_optional_bytes_to_json_empty() {
let json_str = CString::new("{}").unwrap();
let ptr = json_str.as_ptr() as *const c_char;
let ptr = json_str.as_ptr().cast::<c_char>();
let result = unsafe { optional_bytes_to_json(ptr) };
assert_eq!(result, Some(HashMap::new()));
}
Expand Down Expand Up @@ -200,7 +200,7 @@ mod tests {
#[rstest]
fn test_bytes_to_string_vec_valid() {
let json_str = CString::new(r#"["value1", "value2", "value3"]"#).unwrap();
let ptr = json_str.as_ptr() as *const c_char;
let ptr = json_str.as_ptr().cast::<c_char>();
let result = unsafe { bytes_to_string_vec(ptr) };

let expected_vec = vec!["value1", "value2", "value3"]
Expand All @@ -214,7 +214,7 @@ mod tests {
#[rstest]
fn test_bytes_to_string_vec_invalid() {
let json_str = CString::new(r#"["value1", 42, "value3"]"#).unwrap();
let ptr = json_str.as_ptr() as *const c_char;
let ptr = json_str.as_ptr().cast::<c_char>();
let result = unsafe { bytes_to_string_vec(ptr) };

let expected_vec = vec!["value1", "value3"]
Expand All @@ -228,7 +228,7 @@ mod tests {
#[rstest]
fn test_optional_bytes_to_json_valid() {
let json_str = CString::new(r#"{"key1": "value1", "key2": 2}"#).unwrap();
let ptr = json_str.as_ptr() as *const c_char;
let ptr = json_str.as_ptr().cast::<c_char>();
let result = unsafe { optional_bytes_to_json(ptr) };
let mut expected_map = HashMap::new();
expected_map.insert("key1".to_owned(), Value::String("value1".to_owned()));
Expand All @@ -242,7 +242,7 @@ mod tests {
#[rstest]
fn test_optional_bytes_to_json_invalid() {
let json_str = CString::new(r#"{"key1": "value1", "key2": }"#).unwrap();
let ptr = json_str.as_ptr() as *const c_char;
let ptr = json_str.as_ptr().cast::<c_char>();
let result = unsafe { optional_bytes_to_json(ptr) };
assert_eq!(result, None);
}
Expand Down
4 changes: 2 additions & 2 deletions nautilus_core/core/src/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ mod tests {
fn test_bytes_to_usize_valid() {
let payload: Vec<u8> = vec![0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08];
let result = bytes_to_usize(&payload).unwrap();
assert_eq!(result, 0x0807060504030201);
assert_eq!(result, 578437695752307201);
assert_eq!(result, 0x0807_0605_0403_0201);
assert_eq!(result, 578_437_695_752_307_201);
}
}
4 changes: 2 additions & 2 deletions nautilus_core/core/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,11 @@ impl AtomicTime {
}

pub fn make_realtime(&self) {
self.realtime.store(true, Ordering::Relaxed)
self.realtime.store(true, Ordering::Relaxed);
}

pub fn make_static(&self) {
self.realtime.store(false, Ordering::Relaxed)
self.realtime.store(false, Ordering::Relaxed);
}
}

Expand Down
12 changes: 6 additions & 6 deletions nautilus_core/network/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ mod tests {

async fn start_test_server() -> Result<SocketAddr, Box<dyn std::error::Error + Send + Sync>> {
let port = get_unique_port();
let listener = tokio::net::TcpListener::bind(format!("127.0.0.1:{}", port))
let listener = tokio::net::TcpListener::bind(format!("127.0.0.1:{port}"))
.await
.unwrap();
let addr = listener.local_addr().unwrap();
Expand All @@ -299,7 +299,7 @@ mod tests {
#[tokio::test]
async fn test_get() {
let addr = start_test_server().await.unwrap();
let url = format!("http://{}", addr);
let url = format!("http://{addr}");

let client = InnerHttpClient::default();
let response = client
Expand All @@ -319,7 +319,7 @@ mod tests {
#[tokio::test]
async fn test_post() {
let addr = start_test_server().await.unwrap();
let url = format!("http://{}", addr);
let url = format!("http://{addr}");

let client = InnerHttpClient::default();
let response = client
Expand All @@ -338,7 +338,7 @@ mod tests {
#[tokio::test]
async fn test_post_with_body() {
let addr = start_test_server().await.unwrap();
let url = format!("http://{}", addr);
let url = format!("http://{addr}");

let client = InnerHttpClient::default();

Expand Down Expand Up @@ -371,7 +371,7 @@ mod tests {
#[tokio::test]
async fn test_patch() {
let addr = start_test_server().await.unwrap();
let url = format!("http://{}", addr);
let url = format!("http://{addr}");

let client = InnerHttpClient::default();
let response = client
Expand All @@ -390,7 +390,7 @@ mod tests {
#[tokio::test]
async fn test_delete() {
let addr = start_test_server().await.unwrap();
let url = format!("http://{}", addr);
let url = format!("http://{addr}");

let client = InnerHttpClient::default();
let response = client
Expand Down

0 comments on commit 73b4729

Please sign in to comment.