use crate::{AnyOutput, ChainProcess, Grouped, ProgramCollect, RenderResult}; #[cfg(feature = "async")] use std::pin::Pin; #[cfg(feature = "dispatch_tree")] use crate::Dispatcher; #[cfg(feature = "comp")] use crate::{ShellContext, Suggest}; #[cfg(feature = "structural_renderer")] use crate::{StructuralRendererSetting, error::StructuralRendererSerializeError}; #[cfg(feature = "structural_renderer")] use serde::Serialize; /// Used to simulate the types generated by the `gen_program!` macro in examples and tests. /// /// It can be referenced in documentation using the following code: /// /// ```rust,ignore /// use mingling_core::MockProgramCollect as ThisProgram; /// ``` /// /// This enum is for development and testing purposes only and should not be used in production code. /// It simulates the program enum type generated by the `gen_program!` macro, allowing examples, unit tests, and doctests to work without actual macro expansion. /// /// # Variants /// /// - `Foo` — Simulates the first program node ID of the program. /// - `Bar` — Simulates the second program node ID of the program. /// /// # Safety Notes /// /// This type implements the `ProgramCollect` trait, but all actual methods are implemented via `unreachable!()` or `panic!`, /// ensuring it will never be called in a real macro system. It is only used to satisfy trait bounds so that type checking passes at compile time. #[cfg_attr(feature = "structural_renderer", derive(Serialize))] #[allow(unused)] #[doc(hidden)] #[derive(Clone, Copy, PartialEq, Eq)] pub enum MockProgramCollect { Foo, Bar, } impl std::fmt::Debug for MockProgramCollect { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { Self::Foo => write!(f, "Foo"), Self::Bar => write!(f, "Bar"), } } } impl std::fmt::Display for MockProgramCollect { fn fmt(&self, _f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { todo!() } } /// SAFETY: This is a mock type used only for temporary testing. /// It will never actually enter the macro system. /// The internal `panic!` ensures that `member_id` will never be executed. unsafe impl Grouped for MockProgramCollect { fn member_id() -> Self { panic!("Attempting to read an unsafe enum type"); } } impl ProgramCollect for MockProgramCollect { type Enum = Self; type EntryFallback = Self; type ErrorRendererNotFound = Self; type ResultEmpty = Self; #[cfg(feature = "dispatch_tree")] fn dispatch_args_trie( _raw: &[String], ) -> Result, crate::error::ProgramInternalExecuteError> { unreachable!() } #[cfg(feature = "dispatch_tree")] fn get_nodes() -> Vec<(String, &'static (dyn Dispatcher + Send + Sync))> { unreachable!() } fn build_renderer_not_found(_member_id: Self::Enum) -> AnyOutput { unreachable!() } fn build_entry_fallback(_args: Vec) -> AnyOutput { unreachable!() } fn build_empty_result() -> AnyOutput { unreachable!() } fn render(_any: AnyOutput) -> RenderResult { unreachable!() } fn render_help(_any: AnyOutput) -> RenderResult { unreachable!() } #[cfg(feature = "async")] fn do_chain( _any: AnyOutput, ) -> Pin> + Send>> { unreachable!() } #[cfg(not(feature = "async"))] fn do_chain(_any: AnyOutput) -> ChainProcess { unreachable!() } #[cfg(feature = "comp")] fn do_comp(_any: &AnyOutput, _ctx: &ShellContext) -> Suggest { unreachable!() } fn has_renderer(_any: &AnyOutput) -> bool { unreachable!() } fn has_chain(_any: &AnyOutput) -> bool { unreachable!() } #[cfg(feature = "structural_renderer")] fn structural_render( _any: AnyOutput, _setting: &StructuralRendererSetting, ) -> Result { unreachable!() } }