From 1c065ed5ec1c1036d185dea91b2f0394d9ddd111 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Mon, 10 Aug 2026 16:21:51 +0800 Subject: refactor: use `Self` and simplify lifetimes in setup types Replace `ThisProgram` with `Self` where appropriate and mark constructors as `#[must_use]` and `const` where possible. Simplify explicit lifetimes in `ProgramSetup` and `Default` implementations using elided lifetimes. --- mingling/src/gen_program.rs | 10 ++++++---- mingling/src/setups/picker/basic.rs | 21 ++++++++++++--------- 2 files changed, 18 insertions(+), 13 deletions(-) (limited to 'mingling/src') diff --git a/mingling/src/gen_program.rs b/mingling/src/gen_program.rs index ef32074..90860b6 100644 --- a/mingling/src/gen_program.rs +++ b/mingling/src/gen_program.rs @@ -184,7 +184,7 @@ unsafe impl Grouped for CompletionSuggest { } impl ProgramCollect for ThisProgram { - type Enum = ThisProgram; + type Enum = Self; type EntryFallback = EntryFallback; @@ -260,13 +260,15 @@ impl ProgramCollect for ThisProgram { } impl ThisProgram { - /// Create a program through this ProgramCollect. - pub fn new() -> Program { + /// Create a program through this `ProgramCollect`. + #[must_use] + pub fn new() -> Program { todo!() } /// Get the global singleton of the current program. - pub fn this() -> &'static Program { + #[must_use] + pub fn this() -> &'static Program { todo!() } } diff --git a/mingling/src/setups/picker/basic.rs b/mingling/src/setups/picker/basic.rs index 7f70eab..24276d2 100644 --- a/mingling/src/setups/picker/basic.rs +++ b/mingling/src/setups/picker/basic.rs @@ -36,12 +36,13 @@ pub struct HelpFlagSetup<'a> { impl<'a> HelpFlagSetup<'a> { /// Creates a new `HelpFlagSetup` with the given flag aliases. - pub fn new(flag: &'a PickerArg) -> Self { + #[must_use] + pub const fn new(flag: &'a PickerArg) -> Self { Self { flag } } } -impl<'a, C> ProgramSetup for HelpFlagSetup<'a> +impl ProgramSetup for HelpFlagSetup<'_> where C: ProgramCollect, { @@ -53,7 +54,7 @@ where } } -impl<'a> Default for HelpFlagSetup<'a> { +impl Default for HelpFlagSetup<'_> { fn default() -> Self { Self { flag: &HELP_FLAG } } @@ -68,12 +69,13 @@ pub struct QuietFlagSetup<'a> { impl<'a> QuietFlagSetup<'a> { /// Creates a new `QuietFlagSetup` with the given flag aliases. - pub fn new(flag: &'a PickerArg) -> Self { + #[must_use] + pub const fn new(flag: &'a PickerArg) -> Self { Self { flag } } } -impl<'a, C> ProgramSetup for QuietFlagSetup<'a> +impl ProgramSetup for QuietFlagSetup<'_> where C: ProgramCollect, { @@ -86,7 +88,7 @@ where } } -impl<'a> Default for QuietFlagSetup<'a> { +impl Default for QuietFlagSetup<'_> { fn default() -> Self { Self { flag: &QUIET_FLAG } } @@ -101,12 +103,13 @@ pub struct ConfirmFlagSetup<'a> { impl<'a> ConfirmFlagSetup<'a> { /// Creates a new `ConfirmFlagSetup` with the given flag aliases. - pub fn new(flag: &'a PickerArg) -> Self { + #[must_use] + pub const fn new(flag: &'a PickerArg) -> Self { Self { flag } } } -impl<'a, C> ProgramSetup for ConfirmFlagSetup<'a> +impl ProgramSetup for ConfirmFlagSetup<'_> where C: ProgramCollect, { @@ -120,7 +123,7 @@ where } } -impl<'a> Default for ConfirmFlagSetup<'a> { +impl Default for ConfirmFlagSetup<'_> { fn default() -> Self { Self { flag: &CONFIRM_FLAG, -- cgit