From 9d328ee87bb65a0cb9b4bd2d4f7611229435a703 Mon Sep 17 00:00:00 2001 From: Jan-Peter von Hunnius Date: Fri, 27 Feb 2026 06:59:45 +0100 Subject: [PATCH] docs: make Intel400xComponentBehavior trait examples testable --- src/components/common/intel_400x.rs | 41 ++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/src/components/common/intel_400x.rs b/src/components/common/intel_400x.rs index 470179b..8d7c6ca 100644 --- a/src/components/common/intel_400x.rs +++ b/src/components/common/intel_400x.rs @@ -592,10 +592,11 @@ pub enum Intel400xEvent { /// /// # Example /// -/// ```rust,ignore +/// ```rust /// use std::time::Duration; /// use rusty_emu::components::common::intel_400x::{ -/// Intel400xComponentBehavior, Intel400xComponentType, Intel400xUnifiedState +/// Intel400xComponentBehavior, Intel400xComponentType, Intel400xUnifiedState, +/// Intel400xEvent /// }; /// /// struct MyCustomComponent { @@ -619,7 +620,23 @@ pub enum Intel400xEvent { /// } /// } /// -/// // ... implement other methods +/// fn on_state_exit(&mut self, _state: Intel400xUnifiedState) { +/// // Cleanup when exiting a state +/// } +/// +/// fn handle_component_event(&mut self, _event: Intel400xEvent) -> bool { +/// // Return true to handle event, false to let state machine process it +/// false +/// } +/// +/// fn execute_state_logic(&mut self, _state: Intel400xUnifiedState) { +/// // Execute state-specific logic +/// } +/// +/// fn responds_to_address(&self) -> bool { +/// // Most components respond to address transmission +/// true +/// } /// } /// ``` pub trait Intel400xComponentBehavior { @@ -646,7 +663,10 @@ pub trait Intel400xComponentBehavior { /// /// # Example /// - /// ```rust,ignore + /// ```rust,no_run + /// use rusty_emu::components::common::intel_400x::Intel400xUnifiedState; + /// # struct MyComponent { address_high_nibble: Option, address_low_nibble: Option } + /// # impl MyComponent { /// fn on_state_entry(&mut self, state: Intel400xUnifiedState) { /// match state { /// Intel400xUnifiedState::AddressPhase => { @@ -656,11 +676,12 @@ pub trait Intel400xComponentBehavior { /// } /// Intel400xUnifiedState::DriveData => { /// // Prepare data for output - /// self.prepare_output_data(); + /// // self.prepare_output_data(); /// } /// _ => {} /// } /// } + /// # } /// ``` fn on_state_entry(&mut self, state: Intel400xUnifiedState); @@ -704,7 +725,14 @@ pub trait Intel400xComponentBehavior { /// /// # Example /// - /// ```rust,ignore + /// ```rust,no_run + /// use rusty_emu::components::common::intel_400x::Intel400xUnifiedState; + /// # struct MyComponent { current_address: u16 } + /// # impl MyComponent { + /// # fn read_data_bus(&self) -> u8 { 0 } + /// # fn latch_address_nibble(&mut self, _nibble: u8) {} + /// # fn read_memory(&self, _addr: u16) -> u8 { 0 } + /// # fn write_data_bus(&self, _data: u8) {} /// fn execute_state_logic(&mut self, state: Intel400xUnifiedState) { /// match state { /// Intel400xUnifiedState::AddressPhase => { @@ -720,6 +748,7 @@ pub trait Intel400xComponentBehavior { /// _ => {} /// } /// } + /// # } /// ``` fn execute_state_logic(&mut self, state: Intel400xUnifiedState);