From 5d91f0e9408e39afaa75f96b32c5ed7946a558f7 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Sun, 29 Mar 2026 14:06:50 +0800 Subject: Add fallback dispatcher for missing renderers. --- mingling/src/program/exec.rs | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) (limited to 'mingling/src/program/exec.rs') diff --git a/mingling/src/program/exec.rs b/mingling/src/program/exec.rs index 99eb419..04ed16d 100644 --- a/mingling/src/program/exec.rs +++ b/mingling/src/program/exec.rs @@ -1,7 +1,7 @@ use crate::{ AnyOutput, ChainProcess, Dispatcher, Program, ProgramCollect, RenderResult, error::{ChainProcessError, ProgramInternalExecuteError}, - hint::{DispatcherNotFound, NoChainFound, ProgramEnd}, + hint::{DispatcherNotFound, NoChainFound, ProgramEnd, RendererNotFound}, }; pub mod error; @@ -30,10 +30,33 @@ pub async fn exec( }; loop { - current = match handle_chain_process::(C::do_chain(current).await) { - Ok(Next::RenderResult(render_result)) => return Ok(render_result), - Ok(Next::AnyOutput(any)) => any, - Err(e) => return Err(e), + current = { + // If a chain exists, execute as a chain + if C::has_chain(¤t) { + match handle_chain_process::(C::do_chain(current).await) { + Ok(Next::RenderResult(render_result)) => return Ok(render_result), + Ok(Next::AnyOutput(any)) => any, + Err(e) => return Err(e), + } + } + // If no chain exists, attempt to render + else if C::has_renderer(¤t) { + let mut render_result = RenderResult::default(); + C::render(current, &mut render_result); + return Ok(render_result); + } + // If no renderer exists, transfer to the RendererNotFound Dispatcher for execution + else { + let disp: Box = Box::new(RendererNotFound); + let any = match handle_chain_process::( + disp.begin(vec![format!("{:?}", current.type_id)]), + ) { + Ok(Next::AnyOutput(any)) => any, + Ok(Next::RenderResult(result)) => return Ok(result), + Err(e) => return Err(e), + }; + any + } }; if current.is::() || current.is::() { break; -- cgit