From c6ab865d5b19e3a57b76562adb9540cbf03d77c4 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Mon, 17 Aug 2026 06:57:09 +0800 Subject: feat(macros): relax completion attribute signature Allow completion functions to omit the context parameter, accept owned ShellContext or any From<&ShellContext> type, and return any type implementing Into. Add From<&str> for SuggestItem and derive Clone for ShellContext. --- mingling_core/src/comp/shell_ctx.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'mingling_core/src/comp/shell_ctx.rs') diff --git a/mingling_core/src/comp/shell_ctx.rs b/mingling_core/src/comp/shell_ctx.rs index 552e514..3a1b8f2 100644 --- a/mingling_core/src/comp/shell_ctx.rs +++ b/mingling_core/src/comp/shell_ctx.rs @@ -96,7 +96,7 @@ use std::collections::HashSet; /// If the `-F` flag is present without a value, `shell_flag` becomes /// `ShellFlag::Other(String::new())`. If `-F` is absent, it defaults to /// `ShellFlag::Other("unknown".to_string())`. -#[derive(Default, Debug)] +#[derive(Default, Debug, Clone)] #[cfg_attr(feature = "structural_renderer", derive(serde::Serialize))] pub struct ShellContext { /// The full command line @@ -182,6 +182,12 @@ impl TryFrom> for ShellContext { } } +impl From<&Self> for ShellContext { + fn from(ctx: &Self) -> Self { + ctx.clone() + } +} + impl ShellContext { /// Checks if a flag appears exactly once in the command line arguments. /// -- cgit