Skip to content

Commit

Permalink
Replace String with &str for error msg
Browse files Browse the repository at this point in the history
  • Loading branch information
qoqosz committed Aug 12, 2024
1 parent 4e8363e commit 551ca96
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/book.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub enum OrderBookResult {
OrderId(u64), // passive placement
Trades(Vec<Trade>), // order matched
OrderIdTrades(u64, Vec<Trade>), // order partially matched
Error(String), // error
Error(&'static str), // error
Canceled, // order canceled
}

Expand Down Expand Up @@ -130,15 +130,15 @@ impl OrderBook {

return OrderBookResult::Canceled;
} else {
return OrderBookResult::Error("Order does not exist".to_string());
return OrderBookResult::Error("Order does not exist");
}
}

fn validate_order(&self, order: &Order) -> Result<(), String> {
fn validate_order(&self, order: &Order) -> Result<(), &'static str> {
if order.size > 0 && order.price > 0.0 {
return Ok(());
}
Err("Non-positive price or quantity for an order".to_string())
Err("Non-positive price or quantity for an order")
}

fn place_passive(&mut self, order: Order) -> u64 {
Expand Down Expand Up @@ -228,7 +228,7 @@ impl OrderBook {

/// Best bid price
pub fn best_bid(&self) -> Option<f64> {
self.bids.keys().rev().next().map(|bid| (*bid).into())
self.bids.keys().rev().next().map(|bid| bid.into_inner())
}

/// Volume of all orders at best bid price
Expand All @@ -237,7 +237,7 @@ impl OrderBook {
}

pub fn best_ask(&self) -> Option<f64> {
self.asks.keys().next().map(|ask| (*ask).into())
self.asks.keys().next().map(|ask| ask.into_inner())
}

pub fn best_ask_size(&self) -> Option<u64> {
Expand Down

0 comments on commit 551ca96

Please sign in to comment.