diff options
| -rw-r--r-- | mingling_core/src/program.rs | 2 | ||||
| -rw-r--r-- | mingling_core/src/program/exec.rs | 5 | ||||
| -rw-r--r-- | mingling_macros/src/lib.rs | 20 |
3 files changed, 15 insertions, 12 deletions
diff --git a/mingling_core/src/program.rs b/mingling_core/src/program.rs index 1c8c0b4..ffba17e 100644 --- a/mingling_core/src/program.rs +++ b/mingling_core/src/program.rs @@ -88,6 +88,8 @@ where pub trait ProgramCollect { type Enum: Display; + fn build_renderer_not_found(member_id: Self::Enum) -> AnyOutput<Self::Enum>; + fn build_dispatcher_not_found(args: Vec<String>) -> AnyOutput<Self::Enum>; fn render(any: AnyOutput<Self::Enum>, r: &mut RenderResult); fn do_chain( any: AnyOutput<Self::Enum>, diff --git a/mingling_core/src/program/exec.rs b/mingling_core/src/program/exec.rs index cdbb2b0..bf025fd 100644 --- a/mingling_core/src/program/exec.rs +++ b/mingling_core/src/program/exec.rs @@ -28,7 +28,7 @@ where } Err(ProgramInternalExecuteError::DispatcherNotFound) => { // No matching Dispatcher is found - return Err(ProgramInternalExecuteError::DispatcherNotFound); + current = C::build_dispatcher_not_found(program.args); } Err(e) => return Err(e), }; @@ -51,8 +51,7 @@ where } // No renderer exists else { - let renderer_name = current.member_id.to_string(); - return Err(ProgramInternalExecuteError::RendererNotFound(renderer_name)); + C::build_renderer_not_found(current.member_id) } }; } diff --git a/mingling_macros/src/lib.rs b/mingling_macros/src/lib.rs index 832b45a..5a32075 100644 --- a/mingling_macros/src/lib.rs +++ b/mingling_macros/src/lib.rs @@ -73,7 +73,11 @@ pub fn gen_program(input: TokenStream) -> TokenStream { parse_macro_input!(input as Ident) }; - let packed_types = PACKED_TYPES.lock().unwrap().clone(); + let mut packed_types = PACKED_TYPES.lock().unwrap().clone(); + packed_types.push("DispatcherNotFound".to_string()); + packed_types.push("RendererNotFound".to_string()); + packed_types.sort(); + packed_types.dedup(); let renderers = RENDERERS.lock().unwrap().clone(); let chains = CHAINS.lock().unwrap().clone(); let renderer_exist = RENDERERS_EXIST.lock().unwrap().clone(); @@ -113,8 +117,6 @@ pub fn gen_program(input: TokenStream) -> TokenStream { pub enum #name { #[default] __FallBack, - DispatcherNotFound, - RendererNotFound, #(#packed_types),* } @@ -122,12 +124,6 @@ pub fn gen_program(input: TokenStream) -> TokenStream { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { match self { #name::__FallBack => write!(f, "__FallBack"), - #name::DispatcherNotFound => { - write!(f, "DispatcherNotFound") - } - #name::RendererNotFound => { - write!(f, "RendererNotFound") - } #(#name::#packed_types => write!(f, stringify!(#packed_types)),)* } } @@ -135,6 +131,12 @@ pub fn gen_program(input: TokenStream) -> TokenStream { impl ::mingling::ProgramCollect for #name { type Enum = #name; + fn build_renderer_not_found(member_id: Self::Enum) -> ::mingling::AnyOutput<Self::Enum> { + ::mingling::AnyOutput::new(RendererNotFound::new(member_id.to_string())) + } + fn build_dispatcher_not_found(args: Vec<String>) -> ::mingling::AnyOutput<Self::Enum> { + ::mingling::AnyOutput::new(DispatcherNotFound::new(args)) + } ::mingling::__dispatch_program_renderers!( #(#renderer_tokens)* ); |
