aboutsummaryrefslogtreecommitdiff
path: root/mingling_core/src/program/collection/mock.rs
blob: 634d52931b4c1e247aeb22900062384115ebbed4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
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<Self> 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<AnyOutput<Self::Enum>, crate::error::ProgramInternalExecuteError> {
        unreachable!()
    }

    #[cfg(feature = "dispatch_tree")]
    fn get_nodes() -> Vec<(String, &'static (dyn Dispatcher<Self::Enum> + Send + Sync))> {
        unreachable!()
    }

    fn build_renderer_not_found(_member_id: Self::Enum) -> AnyOutput<Self::Enum> {
        unreachable!()
    }

    fn build_entry_fallback(_args: Vec<String>) -> AnyOutput<Self::Enum> {
        unreachable!()
    }

    fn build_empty_result() -> AnyOutput<Self::Enum> {
        unreachable!()
    }

    fn render(_any: AnyOutput<Self::Enum>) -> RenderResult {
        unreachable!()
    }

    fn render_help(_any: AnyOutput<Self::Enum>) -> RenderResult {
        unreachable!()
    }

    #[cfg(feature = "async")]
    fn do_chain(
        _any: AnyOutput<Self::Enum>,
    ) -> Pin<Box<dyn Future<Output = ChainProcess<Self::Enum>> + Send>> {
        unreachable!()
    }

    #[cfg(not(feature = "async"))]
    fn do_chain(_any: AnyOutput<Self::Enum>) -> ChainProcess<Self::Enum> {
        unreachable!()
    }

    #[cfg(feature = "comp")]
    fn do_comp(_any: &AnyOutput<Self::Enum>, _ctx: &ShellContext) -> Suggest {
        unreachable!()
    }

    fn has_renderer(_any: &AnyOutput<Self::Enum>) -> bool {
        unreachable!()
    }

    fn has_chain(_any: &AnyOutput<Self::Enum>) -> bool {
        unreachable!()
    }

    #[cfg(feature = "structural_renderer")]
    fn structural_render(
        _any: AnyOutput<Self::Enum>,
        _setting: &StructuralRendererSetting,
    ) -> Result<RenderResult, StructuralRendererSerializeError> {
        unreachable!()
    }
}