diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2021-12-28 14:57:41 +0100 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2021-12-28 14:57:41 +0100 |
commit | dacc05a41b77bf2e86e27ac354db9b047c661a7d (patch) | |
tree | 3d71fa60ff3449f73ec8bb6066ae82733eb46ee4 /planetwars-cli/src/web/mod.rs | |
parent | 5ca8dd4c842ee681ce81a6a7bbd5005cd5b98d3c (diff) | |
download | planetwars.dev-dacc05a41b77bf2e86e27ac354db9b047c661a7d.tar.xz planetwars.dev-dacc05a41b77bf2e86e27ac354db9b047c661a7d.zip |
refactor workspace code
Diffstat (limited to 'planetwars-cli/src/web/mod.rs')
-rw-r--r-- | planetwars-cli/src/web/mod.rs | 18 |
1 files changed, 9 insertions, 9 deletions
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<Arc<State>>) -> Json<Vec<MatchData>> { 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<MatchMeta> { } async fn get_match(Extension(state): Extension<Arc<State>>, Path(id): Path<String>) -> 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() } |