From dacc05a41b77bf2e86e27ac354db9b047c661a7d Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Tue, 28 Dec 2021 14:57:41 +0100 Subject: refactor workspace code --- planetwars-cli/src/web/mod.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'planetwars-cli/src/web/mod.rs') diff --git a/planetwars-cli/src/web/mod.rs b/planetwars-cli/src/web/mod.rs index 8394897..676d7af 100644 --- a/planetwars-cli/src/web/mod.rs +++ b/planetwars-cli/src/web/mod.rs @@ -18,20 +18,20 @@ use std::{ sync::Arc, }; -use crate::match_runner::MatchMeta; +use crate::{match_runner::MatchMeta, workspace::Workspace}; struct State { - workspace_root: PathBuf, + workspace: Workspace, } impl State { - fn new(workspace_root: PathBuf) -> Self { - Self { workspace_root } + fn new(workspace: Workspace) -> Self { + Self { workspace } } } -pub async fn run(workspace_root: PathBuf) { - let shared_state = Arc::new(State::new(workspace_root)); +pub async fn run(workspace: Workspace) { + let shared_state = Arc::new(State::new(workspace)); // build our application with a route let app = Router::new() @@ -80,8 +80,8 @@ struct MatchData { async fn list_matches(Extension(state): Extension>) -> Json> { let matches = state - .workspace_root - .join("matches") + .workspace + .matches_dir() .read_dir() .unwrap() .filter_map(|entry| { @@ -125,7 +125,7 @@ fn read_match_meta(path: &path::Path) -> io::Result { } async fn get_match(Extension(state): Extension>, Path(id): Path) -> String { - let mut match_path = state.workspace_root.join("matches").join(id); + let mut match_path = state.workspace.matches_dir().join(id); match_path.set_extension("log"); fs::read_to_string(match_path).unwrap() } -- cgit v1.2.3