Skip to content

Commit

Permalink
Standardize use of u8_as_bool
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdsellers committed Nov 12, 2023
1 parent 9ff7a6d commit 5711da2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
7 changes: 5 additions & 2 deletions nautilus_core/backtest/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
use std::ops::{Deref, DerefMut};

use nautilus_common::{clock::TestClock, ffi::clock::TestClock_API, timer::TimeEventHandler};
use nautilus_core::{ffi::cvec::CVec, time::UnixNanos};
use nautilus_core::{
ffi::{cvec::CVec, parsing::u8_as_bool},
time::UnixNanos,
};

/// Provides a means of accumulating and draining time event handlers.
pub struct TimeEventAccumulator {
Expand Down Expand Up @@ -93,7 +96,7 @@ pub extern "C" fn time_event_accumulator_advance_clock(
to_time_ns: UnixNanos,
set_time: u8,
) {
accumulator.advance_clock(clock, to_time_ns, set_time != 0);
accumulator.advance_clock(clock, to_time_ns, u8_as_bool(set_time));
}

#[no_mangle]
Expand Down
4 changes: 2 additions & 2 deletions nautilus_core/common/src/ffi/clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::{
};

use nautilus_core::{
ffi::{cvec::CVec, string::cstr_to_string},
ffi::{cvec::CVec, parsing::u8_as_bool, string::cstr_to_string},
time::UnixNanos,
};
use pyo3::{
Expand Down Expand Up @@ -199,7 +199,7 @@ pub unsafe extern "C" fn test_clock_advance_time(
to_time_ns: u64,
set_time: u8,
) -> CVec {
let events: Vec<TimeEvent> = clock.advance_time(to_time_ns, set_time != 0);
let events: Vec<TimeEvent> = clock.advance_time(to_time_ns, u8_as_bool(set_time));
clock.match_handlers(events).into()
}

Expand Down
8 changes: 4 additions & 4 deletions nautilus_core/common/src/ffi/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use std::{

use nautilus_core::{
ffi::{
parsing::optional_bytes_to_json,
parsing::{optional_bytes_to_json, u8_as_bool},
string::{cstr_to_string, optional_cstr_to_string, str_to_cstr},
},
uuid::UUID4,
Expand Down Expand Up @@ -89,7 +89,7 @@ pub unsafe extern "C" fn logger_new(
String::from(&cstr_to_string(machine_id_ptr)),
UUID4::from(cstr_to_string(instance_id_ptr).as_str()),
level_stdout,
if file_logging != 0 {
if u8_as_bool(file_logging) {
Some(level_file)
} else {
None
Expand All @@ -98,8 +98,8 @@ pub unsafe extern "C" fn logger_new(
optional_cstr_to_string(file_name_ptr),
optional_cstr_to_string(file_format_ptr),
optional_bytes_to_json(component_levels_ptr),
is_colored != 0,
is_bypassed != 0,
u8_as_bool(is_colored),
u8_as_bool(is_bypassed),
)))
}

Expand Down
2 changes: 1 addition & 1 deletion nautilus_core/core/src/ffi/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ pub unsafe extern "C" fn precision_from_cstr(ptr: *const c_char) -> u8 {

/// Return a `bool` value from the given `u8`.
#[must_use]
pub fn u8_to_bool(value: u8) -> bool {
pub fn u8_as_bool(value: u8) -> bool {
value != 0
}

Expand Down

0 comments on commit 5711da2

Please sign in to comment.