From: Ian Jackson Date: Sun, 2 May 2021 23:12:06 +0000 (+0100) Subject: config: Make ServerConfigSpec::resolve() not TryFrom X-Git-Tag: otter-0.6.0~463 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=21615309a8d5b75c5da4ffc52895f670d85ad2e2;p=otter.git config: Make ServerConfigSpec::resolve() not TryFrom This changes the cwd! Signed-off-by: Ian Jackson --- diff --git a/src/config.rs b/src/config.rs index cc6d1292..bd8e1af9 100644 --- a/src/config.rs +++ b/src/config.rs @@ -67,17 +67,16 @@ pub struct ServerConfig { pub game_rng: RngWrap, } -impl TryFrom for WholeServerConfig { - type Error = AE; - #[throws(Self::Error)] - fn try_from(spec: ServerConfigSpec) -> WholeServerConfig { +impl ServerConfigSpec { + #[throws(AE)] + pub fn resolve(self) -> WholeServerConfig { let ServerConfigSpec { change_directory, base_dir, save_dir, command_socket, debug, http_port, public_url, sse_wildcard_url, rocket_workers, template_dir, nwtemplate_dir, wasm_dir, log, bundled_sources, shapelibs, sendmail, debug_js_inject_file, check_bundled_sources, fake_rng, - } = spec; + } = self; let game_rng = fake_rng.make_game_rng(); @@ -213,7 +212,7 @@ impl ServerConfig { File::open(&config_filename).with_context(||config_filename.to_string())? .read_to_string(&mut buf)?; let spec: ServerConfigSpec = toml_de::from_str(&buf)?; - let whole = spec.try_into()?; + let whole = spec.resolve()?; set_config(whole); } @@ -244,6 +243,6 @@ impl Default for WholeServerConfig { public_url = "INTERNAL ERROR" "#) .expect("parse dummy config as ServerConfigSpec"); - spec.try_into().expect("empty spec into config") + spec.resolve().expect("empty spec into config") } }