From: Ian Jackson Date: Fri, 29 Apr 2022 21:17:10 +0000 (+0100) Subject: ModifyingPieces: Provide on-your-own-head constructors, and doc X-Git-Tag: otter-1.1.0~418 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=8e05679106697c01e32d54e04ee826f4fd5558b0;p=otter.git ModifyingPieces: Provide on-your-own-head constructors, and doc Signed-off-by: Ian Jackson --- diff --git a/src/global.rs b/src/global.rs index 487d79a7..2feb7cb2 100644 --- a/src/global.rs +++ b/src/global.rs @@ -89,6 +89,10 @@ deref_to_field!{IPiece, IPieceTraitObj, p} #[serde(transparent)] pub struct IPieces(ActualIPieces); pub type ActualIPieces = SecondarySlotMap; + +/// Proof token that it is OK to modify the array +/// +/// This exists to prevent bugs where we forget to save aux #[derive(Copy,Clone,Debug)] pub struct ModifyingPieces(()); @@ -282,6 +286,12 @@ impl Debug for Instance { } } +impl ModifyingPieces { + pub fn allow_without_necessarily_saving() -> ModifyingPieces { + ModifyingPieces(()) + } +} + // ---------- Main API for instance lifecycle ---------- impl InstanceRef { @@ -970,6 +980,12 @@ impl<'ig> InstanceGuard<'ig> { ModifyingPieces(()) } + pub fn modify_pieces_not_necessarily_saving_aux(&mut self) + -> ModifyingPieces { + self.save_game_later(); + ModifyingPieces(()) + } + fn token_register( &mut self, token: RawToken,