Skip to content

Commit

Permalink
Fix clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdsellers committed Nov 11, 2023
1 parent ab953ed commit 4d2510e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
2 changes: 2 additions & 0 deletions nautilus_core/common/src/clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ pub struct TestClock {
}

impl TestClock {
#[must_use]
pub fn new() -> Self {
Self {
time_ns: 0,
Expand Down Expand Up @@ -343,6 +344,7 @@ pub struct LiveClock {
}

impl LiveClock {
#[must_use]
pub fn new() -> Self {
Self {
internal: MonotonicClock::default(),
Expand Down
19 changes: 12 additions & 7 deletions nautilus_core/common/src/msgbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ where
T: Clone,
{
/// Initializes a new instance of the [`MessageBus<T>`].
#[must_use]
pub fn new(trader_id: TraderId, name: Option<String>) -> Self {
Self {
trader_id,
Expand All @@ -158,11 +159,13 @@ where
}

/// Returns the registered endpoint addresses.
#[must_use]
pub fn endpoints(&self) -> Vec<&str> {
self.endpoints.keys().map(|k| k.as_str()).collect()
self.endpoints.keys().map(Ustr::as_str).collect()
}

/// Returns the topics for active subscriptions.
#[must_use]
pub fn topics(&self) -> Vec<&str> {
self.subscriptions
.keys()
Expand Down Expand Up @@ -193,7 +196,7 @@ where

// Find existing patterns which match this topic
let mut matches = Vec::new();
for (pattern, subs) in self.patterns.iter_mut() {
for (pattern, subs) in &mut self.patterns {
if is_matching(&Ustr::from(topic), pattern) {
subs.push(sub.clone());
subs.sort(); // Sort in priority order
Expand All @@ -212,11 +215,13 @@ where
}

/// Returns the handler for the given `endpoint`.
#[must_use]
pub fn get_endpoint(&self, endpoint: &str) -> Option<&T> {
self.endpoints.get(&Ustr::from(endpoint))
}

/// Returns whether there are subscribers for the given `pattern`.
#[must_use]
pub fn has_subscribers(&self, pattern: &str) -> bool {
self.matching_handlers(&Ustr::from(pattern))
.next()
Expand Down Expand Up @@ -378,7 +383,7 @@ mod tests {
let msgbus = MessageBus::<Handler>::new(TraderId::from("trader-001"), None);

assert!(msgbus.topics().is_empty());
assert!(!msgbus.has_subscribers(&"my-topic".to_string()));
assert!(!msgbus.has_subscribers("my-topic"));
}

#[rstest]
Expand All @@ -388,7 +393,7 @@ mod tests {

// Useless handler for testing
let handler = Rc::new(|m: &_| {
format!("{:?}", m);
format!("{m:?}");
});

msgbus.register(endpoint.clone(), handler.clone());
Expand All @@ -404,7 +409,7 @@ mod tests {

// Useless handler for testing
let handler = Rc::new(|m: &_| {
format!("{:?}", m);
format!("{m:?}");
});

msgbus.register(endpoint.clone(), handler.clone());
Expand All @@ -420,7 +425,7 @@ mod tests {

// Useless handler for testing
let handler = Rc::new(|m: &_| {
format!("{:?}", m);
format!("{m:?}");
});

msgbus.subscribe(&topic, handler.clone(), "a", Some(1));
Expand All @@ -436,7 +441,7 @@ mod tests {

// Useless handler for testing
let handler = Rc::new(|m: &_| {
format!("{:?}", m);
format!("{m:?}");
});

msgbus.subscribe(&topic, handler.clone(), "a", None);
Expand Down
1 change: 1 addition & 0 deletions nautilus_core/core/src/python/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ pub fn py_nanos_to_micros(nanos: u64) -> u64 {
nanos_to_micros(nanos)
}

#[must_use]
#[pyfunction(name = "unix_nanos_to_iso8601")]
pub fn py_unix_nanos_to_iso8601(timestamp_ns: u64) -> String {
unix_nanos_to_iso8601(timestamp_ns)
Expand Down

0 comments on commit 4d2510e

Please sign in to comment.