diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-04-19 00:31:05 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-04-19 00:31:05 +0800 |
| commit | 532f4ceba2bddb1c84d2e0bdd69808a3ebd5ca4a (patch) | |
| tree | 043514a2aca670d8b2398726b17aab1066938ba1 /mingling_core/src/program/exec.rs | |
| parent | ecc1329bbd31cd98fa9b4c2f25a3114f133987ae (diff) | |
Make async an optional feature
Diffstat (limited to 'mingling_core/src/program/exec.rs')
| -rw-r--r-- | mingling_core/src/program/exec.rs | 61 |
1 files changed, 61 insertions, 0 deletions
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<C, G>( program: &Program<C, G>, ) -> Result<RenderResult, ProgramInternalExecuteError> @@ -71,6 +72,66 @@ where Ok(RenderResult::default()) } +#[cfg(not(feature = "async"))] +pub fn exec<C, G>(program: &Program<C, G>) -> Result<RenderResult, ProgramInternalExecuteError> +where + C: ProgramCollect<Enum = G>, + 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::<C, G>(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::<C, G>(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::<C, G>(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<C, G>( |
