From 532f4ceba2bddb1c84d2e0bdd69808a3ebd5ca4a Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Sun, 19 Apr 2026 00:31:05 +0800 Subject: Make async an optional feature --- mingling_core/src/program/exec.rs | 61 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) (limited to 'mingling_core/src/program') diff --git a/mingling_core/src/program/exec.rs b/mingling_core/src/program/exec.rs index ff7e92b..8ab2036 100644 --- a/mingling_core/src/program/exec.rs +++ b/mingling_core/src/program/exec.rs @@ -10,6 +10,7 @@ use crate::{ #[doc(hidden)] pub mod error; +#[cfg(feature = "async")] pub async fn exec( program: &Program, ) -> Result @@ -71,6 +72,66 @@ where Ok(RenderResult::default()) } +#[cfg(not(feature = "async"))] +pub fn exec(program: &Program) -> Result +where + C: ProgramCollect, + G: Display, +{ + let mut current; + let mut stop_next = false; + + // Match user input + match match_user_input(program, program.args.clone()) { + Ok((dispatcher, args)) => { + // Entry point + current = match dispatcher.begin(args) { + ChainProcess::Ok((any, Next::Renderer)) => { + return Ok(render::(program, any)); + } + ChainProcess::Ok((any, Next::Chain)) => any, + ChainProcess::Err(e) => return Err(e.into()), + }; + } + Err(ProgramInternalExecuteError::DispatcherNotFound) => { + // No matching Dispatcher is found + current = C::build_dispatcher_not_found(program.args.clone()); + } + Err(e) => return Err(e), + }; + + loop { + let final_exec = stop_next; + + current = { + // If a chain exists, execute as a chain + if C::has_chain(¤t) { + match C::do_chain(current) { + ChainProcess::Ok((any, Next::Renderer)) => { + return Ok(render::(program, any)); + } + ChainProcess::Ok((any, Next::Chain)) => any, + ChainProcess::Err(e) => return Err(e.into()), + } + } + // If no chain exists, attempt to render + else if C::has_renderer(¤t) { + return Ok(render::(program, current)); + } + // No renderer exists + else { + stop_next = true; + C::build_renderer_not_found(current.member_id) + } + }; + + if final_exec && stop_next { + break; + } + } + Ok(RenderResult::default()) +} + /// Match user input against registered dispatchers and return the matched dispatcher and remaining arguments. #[allow(clippy::type_complexity)] pub fn match_user_input( -- cgit