diff options
| author | Serguey Parkhomovsky <xindigo@gmail.com> | 2026-03-17 20:45:02 -0700 |
|---|---|---|
| committer | Serguey Parkhomovsky <xindigo@gmail.com> | 2026-03-17 20:45:02 -0700 |
| commit | b42ed72e7d8f6b0a3538acdc299b1d132f8f22cb (patch) | |
| tree | 408c29e4c30c1caf60b62bc4b26c98e6e79df58b /src/main.rs | |
| parent | d0bb801b908ea2de76779206a462ac99fc87be29 (diff) | |
Minor cleanups
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/main.rs b/src/main.rs index f6ec659..d1e7a03 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,11 +9,15 @@ use std::sync::Arc; use std::time::Duration; use tokio::sync::Mutex; +type StateMap = Arc<Mutex<HashMap<String, PrinterState>>>; + #[tokio::main] async fn main() { + tracing_subscriber::fmt::init(); + let content = fs::read_to_string("config.toml").expect("Couldn't read config.toml"); let config = Config::load(&content); - let state: Arc<Mutex<HashMap<String, PrinterState>>> = Arc::new(Mutex::new(HashMap::new())); + let state: StateMap = Arc::new(Mutex::new(HashMap::new())); for printer in config.printers { match printer { @@ -30,8 +34,6 @@ async fn main() { } } - tracing_subscriber::fmt::init(); - let app = Router::new() .route("/", get(root)) .with_state(state.clone()); @@ -44,7 +46,7 @@ async fn poll_prusa( name: String, host: String, api_key: String, - state: Arc<Mutex<HashMap<String, PrinterState>>>, + state: StateMap, ) { let client = Client::new(); loop { @@ -74,7 +76,7 @@ async fn poll_bambu( host: String, serial_number: String, access_code: String, - state: Arc<Mutex<HashMap<String, PrinterState>>>, + state: StateMap, ) { let mut mqttoptions = MqttOptions::new(&name, &host, 8883); mqttoptions.set_keep_alive(Duration::from_secs(5)); @@ -118,7 +120,7 @@ async fn poll_bambu( } async fn root( - State(state): State<Arc<Mutex<HashMap<String, PrinterState>>>>, + State(state): State<StateMap>, ) -> Json<HashMap<String, PrinterState>> { let lock = state.lock().await; Json(lock.clone()) |
