From: Ian Jackson Date: Sat, 27 Feb 2021 18:51:12 +0000 (+0000) Subject: Rename/refactor MgmtChannelForGame X-Git-Tag: otter-0.4.0~303 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=b331af651563127d5d388b21f087613b29312b37;p=otter.git Rename/refactor MgmtChannelForGame Signed-off-by: Ian Jackson --- diff --git a/src/bin/otter.rs b/src/bin/otter.rs index 6f0d9820..c80b91d0 100644 --- a/src/bin/otter.rs +++ b/src/bin/otter.rs @@ -579,12 +579,11 @@ fn access_account(ma: &MainOpts) -> Conn { } #[throws(AE)] -fn access_game(ma: &MainOpts, table_name: &String) -> ConnForGame { - ConnForGame { - conn: access_account(ma)?.chan, - game: ma.instance_name(table_name), - how: MgmtGameUpdateMode::Online, - } +fn access_game(ma: &MainOpts, table_name: &String) -> MgmtChannelForGame { + access_account(ma)?.chan.for_game( + ma.instance_name(table_name), + MgmtGameUpdateMode::Online, + ) } //---------- list-games ---------- @@ -660,11 +659,10 @@ mod reset_game { fn call(_sc: &Subcommand, ma: MainOpts, args: Vec) ->Result<(),AE> { let args = parse_args::(args, &subargs, &ok_id, None); - let mut chan = ConnForGame { - conn: access_account(&ma)?.chan, - game: ma.instance_name(&args.table_name), - how: MgmtGameUpdateMode::Bulk, - }; + let mut chan = access_account(&ma)?.chan.for_game( + ma.instance_name(&args.table_name), + MgmtGameUpdateMode::Bulk, + ); let GameSpec { table_size, pieces, diff --git a/src/mgmtchannel.rs b/src/mgmtchannel.rs index ed88647c..bd3d5a1b 100644 --- a/src/mgmtchannel.rs +++ b/src/mgmtchannel.rs @@ -104,6 +104,14 @@ impl MgmtChannel { items.sort(); items } + + pub fn for_game(self, game: InstanceName, how: MgmtGameUpdateMode) + -> MgmtChannelForGame { + MgmtChannelForGame { + chan: self, + game, how + } + } } pub trait IoTryClone: Sized { @@ -115,14 +123,14 @@ impl IoTryClone for UnixStream { } -pub struct ConnForGame { - pub conn: MgmtChannel, +pub struct MgmtChannelForGame { + pub chan: MgmtChannel, pub game: InstanceName, pub how: MgmtGameUpdateMode, } -deref_to_field_mut!{ConnForGame, MgmtChannel, conn} +deref_to_field_mut!{MgmtChannelForGame, MgmtChannel, chan} -impl ConnForGame { +impl MgmtChannelForGame { #[throws(AE)] pub fn alter_game(&mut self, insns: Vec, f: Option<&mut dyn FnMut(&MgmtGameResponse) -> Result<(),AE>>)