cleanups & docs

This commit is contained in:
2026-07-07 18:59:12 -07:00
parent 4cd41fbdee
commit b75c35be84
+5 -5
View File
@@ -17,22 +17,20 @@ pub trait Game: Clone {
) -> impl Iterator<Item = Self::Instruction> + use<Self>; ) -> impl Iterator<Item = Self::Instruction> + use<Self>;
fn is_instruction_valid(&self, config: &Self::Config, instruction: &Self::Instruction) -> bool; fn is_instruction_valid(&self, config: &Self::Config, instruction: &Self::Instruction) -> bool;
fn is_win(&self) -> bool; fn is_win(&self) -> bool;
/// Validate an instruction to prepare to run it.
fn stage_instruction<'a>( fn stage_instruction<'a>(
&'a mut self, &'a mut self,
stats: &'a mut Self::Stats, stats: &'a mut Self::Stats,
config: &'a Self::Config, config: &'a Self::Config,
instruction: Self::Instruction, instruction: Self::Instruction,
) -> Option<StagedInstruction<'a, Self>> { ) -> Option<StagedInstruction<'a, Self>> {
if self.is_instruction_valid(config, &instruction) { self.is_instruction_valid(config, &instruction)
Some(StagedInstruction { .then_some(StagedInstruction {
game: self, game: self,
stats, stats,
config, config,
instruction, instruction,
}) })
} else {
None
}
} }
} }
@@ -44,6 +42,7 @@ pub struct StagedInstruction<'a, G: Game> {
instruction: G::Instruction, instruction: G::Instruction,
} }
impl<'a, G: Game> StagedInstruction<'a, G> { impl<'a, G: Game> StagedInstruction<'a, G> {
/// Consume the staged instruction. Use this in your implementation of InstructionConsumer::process_instruction for your game.
pub fn consume(self) -> (&'a mut G, &'a mut G::Stats, &'a G::Config, G::Instruction) { pub fn consume(self) -> (&'a mut G, &'a mut G::Stats, &'a G::Config, G::Instruction) {
let StagedInstruction { let StagedInstruction {
game, game,
@@ -58,6 +57,7 @@ impl<G: Game> StagedInstruction<'_, G>
where where
G: InstructionConsumer, G: InstructionConsumer,
{ {
/// Process the staged instruction.
pub fn commit(self) { pub fn commit(self) {
G::process_instruction(self); G::process_instruction(self);
} }