aboutsummaryrefslogtreecommitdiff
path: root/mingling_core/src/program/collection/mock.rs
blob: b8d881ef09ba9ae62bcfb3846a5a7c122d92f1df (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
// Doc Not Optimize
#[cfg(feature = "async")]
use std::pin::Pin;

#[cfg(feature = "dispatch_tree")]
use crate::Dispatcher;

use crate::{AnyOutput, ChainProcess, Grouped, ProgramCollect, RenderResult};

#[cfg(feature = "structural_renderer")]
use crate::{StructuralRendererSetting, error::StructuralRendererSerializeError};

#[cfg(feature = "comp")]
use crate::{ShellContext, Suggest};

#[cfg(feature = "structural_renderer")]
use serde::Serialize;

#[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!()
    }
}