11use anyhow:: { Context , Result } ;
22use serde:: { Deserialize , Serialize } ;
3- use std:: collections:: HashMap ;
3+ use std:: collections:: BTreeMap ;
44use std:: time:: Duration ;
55use tokio:: time:: sleep;
66
@@ -12,7 +12,7 @@ use mahler::worker::{init_logging, Worker};
1212// since the library uses JSON internally to access parts
1313// of the state
1414#[ derive( Debug , Serialize , Deserialize , PartialEq , Eq ) ]
15- struct Counters ( HashMap < String , i32 > ) ;
15+ struct Counters ( BTreeMap < String , i32 > ) ;
1616
1717// `plus_one` defines a job that updates a counter if it is below some target.
1818// The job makes use of two extractors:
@@ -72,7 +72,7 @@ async fn main() -> Result<()> {
7272 . job ( "/{counter}" , update ( plus_two) )
7373 // We initialize the worker with two counters
7474 // `a` and `b` with value 0
75- . initial_state ( Counters ( HashMap :: from ( [
75+ . initial_state ( Counters ( BTreeMap :: from ( [
7676 ( "a" . to_string ( ) , 0 ) ,
7777 ( "b" . to_string ( ) , 0 ) ,
7878 ] ) ) )
@@ -81,7 +81,7 @@ async fn main() -> Result<()> {
8181 // Tell the worker to find a plan from the initial state (a:0, b:0)
8282 // to the target state (a:1, b:2) and execute it
8383 let worker = worker
84- . seek_target ( Counters ( HashMap :: from ( [
84+ . seek_target ( Counters ( BTreeMap :: from ( [
8585 ( "a" . to_string ( ) , 1 ) ,
8686 ( "b" . to_string ( ) , 2 ) ,
8787 ] ) ) )
@@ -98,7 +98,9 @@ async fn main() -> Result<()> {
9898
9999 assert_eq ! (
100100 state,
101- Counters ( HashMap :: from( [ ( "a" . to_string( ) , 1 ) , ( "b" . to_string( ) , 2 ) , ] ) )
101+ Counters ( BTreeMap :: from(
102+ [ ( "a" . to_string( ) , 1 ) , ( "b" . to_string( ) , 2 ) , ]
103+ ) )
102104 ) ;
103105
104106 println ! ( "The system state is now {:?}" , state) ;
0 commit comments