From 1ab19e8765ea2ed62c8a41113d84867facaabf08 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Mon, 1 Jun 2026 12:55:23 +0800 Subject: Change `ProgramSetup::setup` to consume `self` instead of borrow --- CHANGELOG.md | 2 +- mingling/src/setups/basic.rs | 2 +- mingling/src/setups/exit_code.rs | 2 +- mingling/src/setups/general_renderer.rs | 4 ++-- mingling/src/setups/repl_basic.rs | 8 ++++---- mingling_core/src/program/setup.rs | 7 +++---- mingling_macros/src/program_setup.rs | 2 +- 7 files changed, 13 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cbfdbb0..61805aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,7 +25,7 @@ let value: MyType = unpack_chain_process!(result, MyType); #### **BREAKING CHANGES** (API CHANGES): -None +1. **\[core\]** Changed the signature of `ProgramSetup::setup` from `fn setup(&mut self, program: &mut Program) -> S` to `fn setup(self, program: &mut Program)`, consuming `self` instead of taking a mutable reference. Correspondingly, `Program::with_setup` now accepts `S` by value (`&mut self, setup: S`) instead of by mutable reference (`&mut self, setup: &mut S`). ### Release 0.1.9 (2026-05-29) diff --git a/mingling/src/setups/basic.rs b/mingling/src/setups/basic.rs index 6164c64..3783df0 100644 --- a/mingling/src/setups/basic.rs +++ b/mingling/src/setups/basic.rs @@ -11,7 +11,7 @@ impl ProgramSetup for BasicProgramSetup where C: ProgramCollect, { - fn setup(&mut self, program: &mut Program) { + fn setup(self, program: &mut Program) { program.global_flag(["--quiet", "-q"], |p| { p.stdout_setting.render_output = false; p.stdout_setting.error_output = false; diff --git a/mingling/src/setups/exit_code.rs b/mingling/src/setups/exit_code.rs index 9513363..88742d5 100644 --- a/mingling/src/setups/exit_code.rs +++ b/mingling/src/setups/exit_code.rs @@ -27,7 +27,7 @@ impl ProgramSetup for ExitCodeSetup where C: ProgramCollect + 'static, { - fn setup(&mut self, program: &mut crate::Program) { + fn setup(self, program: &mut crate::Program) { // Insert resource program.with_resource(ExitCode { exit_code: 0 }); diff --git a/mingling/src/setups/general_renderer.rs b/mingling/src/setups/general_renderer.rs index e0a0d61..88f5bfa 100644 --- a/mingling/src/setups/general_renderer.rs +++ b/mingling/src/setups/general_renderer.rs @@ -9,7 +9,7 @@ impl ProgramSetup for GeneralRendererSimpleSetup where C: ProgramCollect, { - fn setup(&mut self, program: &mut Program) { + fn setup(self, program: &mut Program) { program.global_argument("--renderer", |p, renderer| { p.general_renderer_name = renderer.into(); }); @@ -32,7 +32,7 @@ where C: ProgramCollect, { #[allow(unused_variables)] - fn setup(&mut self, program: &mut Program) { + fn setup(self, program: &mut Program) { #[cfg(feature = "json_serde_fmt")] program.global_flag("--json", |p| { p.general_renderer_name = crate::GeneralRendererSetting::Json; diff --git a/mingling/src/setups/repl_basic.rs b/mingling/src/setups/repl_basic.rs index fbb806e..8b9b83f 100644 --- a/mingling/src/setups/repl_basic.rs +++ b/mingling/src/setups/repl_basic.rs @@ -8,7 +8,7 @@ impl ProgramSetup for BasicREPLReadlineSetup where C: ProgramCollect, { - fn setup(&mut self, program: &mut Program) { + fn setup(self, program: &mut Program) { program.with_hook(ProgramHook::empty().on_repl_readline(|| readline().ok())); } } @@ -39,7 +39,7 @@ impl ProgramSetup for BasicREPLPromptSetup where C: ProgramCollect, { - fn setup(&mut self, program: &mut Program) { + fn setup(self, program: &mut Program) { match self { BasicREPLPromptSetup::Prompt(prompt) => { static PROMPT: std::sync::OnceLock = std::sync::OnceLock::new(); @@ -52,7 +52,7 @@ where } BasicREPLPromptSetup::Func(f) => { static FUNC: std::sync::OnceLock String> = std::sync::OnceLock::new(); - let _ = FUNC.set(*f); + let _ = FUNC.set(f); fn print_func_prompt() { print!("{}", FUNC.get().unwrap()()); let _ = std::io::stdout().flush(); @@ -69,7 +69,7 @@ impl ProgramSetup for BasicREPLOutputSetup where C: ProgramCollect, { - fn setup(&mut self, program: &mut Program) { + fn setup(self, program: &mut Program) { program.with_hook(ProgramHook::empty().on_repl_receive_result(|r| { if !r.is_empty() { println!("{}", r.trim()) diff --git a/mingling_core/src/program/setup.rs b/mingling_core/src/program/setup.rs index 0fe8070..fa9d0eb 100644 --- a/mingling_core/src/program/setup.rs +++ b/mingling_core/src/program/setup.rs @@ -4,7 +4,7 @@ pub trait ProgramSetup where C: ProgramCollect, { - fn setup(&mut self, program: &mut Program); + fn setup(self, program: &mut Program); } impl Program @@ -12,8 +12,7 @@ where C: ProgramCollect, { /// Load and execute init logic - pub fn with_setup + 'static>(&mut self, mut setup: S) -> S { - S::setup(&mut setup, self); - setup + pub fn with_setup + 'static>(&mut self, setup: S) { + S::setup(setup, self); } } diff --git a/mingling_macros/src/program_setup.rs b/mingling_macros/src/program_setup.rs index 383d632..d8f9507 100644 --- a/mingling_macros/src/program_setup.rs +++ b/mingling_macros/src/program_setup.rs @@ -105,7 +105,7 @@ pub fn setup_attr(attr: TokenStream, item: TokenStream) -> TokenStream { #vis struct #struct_name; impl ::mingling::setup::ProgramSetup<#program_name> for #struct_name { - fn setup(&mut self, program: &mut ::mingling::Program<#program_name>) { + fn setup(self, program: &mut ::mingling::Program<#program_name>) { // Call the original function with the actual Program type #fn_name(program); } -- cgit