i'm rather use impl fmt::Debug
for ignoring action
in struct while print Order
struct instead of #[derive(Debug)]
like:
struct Order {
id: u64,
price: f64,
action: bool, //action buy=true || action sell=false, i'd like to put "action" word for buy or sell
}
impl fmt::Debug for Order {
fn fmt(&self, formater: &mut fmt::Formatter) -> fmt::Result {
formater
.debug_struct("Order")
.field("id", &self.id)
.field("price", &self.price)
.finish()
}
}
async fn serve_orders(order_list: Vec<Order>) -> impl Stream<Item = Order> {
stream! {
for order in order_list {
let delay_duration = rand::thread_rng().gen_range(500..900);
sleep(Duration::from_millis(delay_duration)).await;
yield order;
}
}
}
async fn execute_orders(order_list: Vec<Order>) {
//accept vector directly
let order_stream = stream! {
for order in order_list {
let delay_duration = rand::thread_rng().gen_range(500..900);
sleep(Duration::from_millis(delay_duration)).await;
yield order;
}
}
futures::pin_mut!(order_stream); //pin the variable of macros stream!
//continue code
}
just type $cargo run .
on terminal