From 9411f2570cbd494aebefa2b97b6b5a1a5e68bb27 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Sun, 19 Apr 2026 00:49:09 +0800 Subject: Remove async runtime requirement from examples --- docs/pages/2-basic/1-program.md | 15 ++++++--------- docs/pages/2-basic/2-setup.md | 5 ++--- docs/pages/2-basic/3-dispatcher.md | 5 ++--- docs/pages/2-basic/4-chain.md | 13 ++++--------- docs/pages/2-basic/5-renderer.md | 9 +++------ 5 files changed, 17 insertions(+), 30 deletions(-) (limited to 'docs/pages/2-basic') diff --git a/docs/pages/2-basic/1-program.md b/docs/pages/2-basic/1-program.md index fd8e986..ae22896 100644 --- a/docs/pages/2-basic/1-program.md +++ b/docs/pages/2-basic/1-program.md @@ -45,12 +45,11 @@ use mingling::{ setup::BasicProgramSetup }; -#[tokio::main] -async fn main() { +fn main() { let mut program = ThisProgram::new(); // Add `BasicProgramSetup` program.with_setup(BasicProgramSetup); - program.exec().await; + program.exec(); } // Generate `ThisProgram` @@ -68,8 +67,7 @@ dispatcher!("member.add", dispatcher!("member.rm", RemoveMemberCommand => RemoveMemberEntry); -#[tokio::main] -async fn main() { +fn main() { let mut program = ThisProgram::new(); // Register Dispatchers @@ -82,7 +80,7 @@ async fn main() { RemoveMemberCommand )); - program.exec().await; + program.exec(); } ``` @@ -91,8 +89,7 @@ async fn main() { You can extract global arguments before the program runs to control the global state of the `Program`: ```rust -#[tokio::main] -async fn main() { +fn main() { let mut program = ThisProgram::new(); let mut output = current_dir().unwrap(); @@ -109,7 +106,7 @@ async fn main() { |_, v| output = PathBuf::from(v) ); - program.exec().await; + program.exec(); } ``` diff --git a/docs/pages/2-basic/2-setup.md b/docs/pages/2-basic/2-setup.md index 8dbdd76..c80b91e 100644 --- a/docs/pages/2-basic/2-setup.md +++ b/docs/pages/2-basic/2-setup.md @@ -38,11 +38,10 @@ use mingling::{ static OUTPUT_PATH: std::sync::OnceLock = std::sync::OnceLock::new(); -#[tokio::main] -async fn main() { +fn main() { let mut program = ThisProgram::new(); program.with_setup(MySetup); - program.exec().await; + program.exec(); } // Define two Dispatchers using `dispatcher!` diff --git a/docs/pages/2-basic/3-dispatcher.md b/docs/pages/2-basic/3-dispatcher.md index d0858d2..66e5c90 100644 --- a/docs/pages/2-basic/3-dispatcher.md +++ b/docs/pages/2-basic/3-dispatcher.md @@ -45,13 +45,12 @@ dispatcher!(MyProgram, "hello", **Tips:** Finally, add the `Dispatcher` you created to the [Program](pages/2-basic/1-program): ```rust -#[tokio::main] -async fn main() { +fn main() { let mut program = ThisProgram::new(); program.with_dispatcher(HelloCommand); program.with_dispatcher(SubFooCommand); program.with_dispatcher(SubBarCommand); - program.exec().await; + program.exec(); } ``` diff --git a/docs/pages/2-basic/4-chain.md b/docs/pages/2-basic/4-chain.md index 87a50f2..0fd375a 100644 --- a/docs/pages/2-basic/4-chain.md +++ b/docs/pages/2-basic/4-chain.md @@ -19,7 +19,7 @@ pack!(ParsedHello = String); // Define chain parse_hello (expands to ParseHello) // Declare conversion from HelloEntry #[chain] -async fn parse_hello(prev: HelloEntry) -> NextProcess { +fn parse_hello(prev: HelloEntry) -> NextProcess { // Take the inner reference of HelloEntry let args = &*prev; @@ -41,10 +41,6 @@ async fn parse_hello(prev: HelloEntry) -> NextProcess { ## Manual Impl -> ⚠️ WARNING -> -> The following content is not yet fully implemented; currently, only the `chain!` macro is allowed for implementation. - You can also manually implement the basic `Chain` for finer control. However, please note that within the `chain!` macro, a `register_type!` macro is executed. This macro does not expand to any content; it only informs the `gen_program` context that this type exists. @@ -58,7 +54,7 @@ pack!(ParsedHello = String); struct ParseHello; impl Chain for ParseHello { type Previous = HelloEntry; - async fn proc(prev: Self::Previous) + fn proc(prev: Self::Previous) -> ChainProcess { let args = &*prev; @@ -72,9 +68,8 @@ impl Chain for ParseHello { } } -// Register HelloEntry to the context and -// assign an ID for it -register_type!(HelloEntry); +// Register chain to the context +register_chain!(HelloEntry); ``` ## 💡 Next Page diff --git a/docs/pages/2-basic/5-renderer.md b/docs/pages/2-basic/5-renderer.md index 1f566f2..12ac00f 100644 --- a/docs/pages/2-basic/5-renderer.md +++ b/docs/pages/2-basic/5-renderer.md @@ -21,7 +21,7 @@ pack!(ParsedHello = String); // It's the Chain defined in the Dispatcher chapter #[chain] -async fn parse_hello(prev: HelloEntry) -> NextProcess { +fn parse_hello(prev: HelloEntry) -> NextProcess { let args = &*prev; let first = args .first() @@ -53,10 +53,6 @@ fn render_hello(prev: ParsedHello) { ## Manual Impl -> ⚠️ WARNING -> -> The following content is not yet fully implemented; currently, only the `renderer!` macro is allowed for implementation. - Similarly, you can also manually implement `Renderer`, but note that inside the `renderer!` macro, a `register_type!` macro is executed. This macro itself does not expand into any content; it is only used to inform the `gen_program` context that the type exists: @@ -73,5 +69,6 @@ impl Renderer for RenderHello { } } -register_type!(ParsedHello); +// Register renderer to the context +register_renderer!(ParsedHello); ``` -- cgit