diff options
| author | Weicao-CatilGrass <1992414357@qq.com> | 2026-05-31 02:42:52 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-05-31 17:19:20 +0800 |
| commit | 2aa7bda3cb21ce6c052b82e08bcab79a625d04f2 (patch) | |
| tree | f10b89007fc67ca1a948f34abe6869b49296b932 /mingling_core/src/comp/shell_ctx.rs | |
| parent | 3aa409a55e4f2f0ab41b0949cc06eb13c2da4a43 (diff) | |
Enhance code quality across the entire codebase
Diffstat (limited to 'mingling_core/src/comp/shell_ctx.rs')
| -rw-r--r-- | mingling_core/src/comp/shell_ctx.rs | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/mingling_core/src/comp/shell_ctx.rs b/mingling_core/src/comp/shell_ctx.rs index 3134cd6..35758e9 100644 --- a/mingling_core/src/comp/shell_ctx.rs +++ b/mingling_core/src/comp/shell_ctx.rs @@ -73,8 +73,7 @@ impl TryFrom<Vec<String>> for ShellContext { let shell_flag = arg_map .get("-F") .cloned() - .map(ShellFlag::from) - .unwrap_or(ShellFlag::Other("unknown".to_string())); + .map_or(ShellFlag::Other("unknown".to_string()), ShellFlag::from); let all_words = command_line .split_whitespace() @@ -120,7 +119,7 @@ impl ShellContext { let flag = flag.into(); if self.filling_argument(&flag) { let mut flag_appears = 0; - for w in self.all_words.iter() { + for w in &self.all_words { for f in flag.iter() { if *f == w { flag_appears += 1; @@ -190,6 +189,7 @@ impl ShellContext { /// // } /// } /// ``` + #[must_use] pub fn typing_argument(&self) -> bool { #[cfg(target_os = "windows")] { @@ -207,6 +207,7 @@ impl ShellContext { /// in the command line. It is useful for preventing duplicate flag suggestions /// when the user has already typed certain flags. The method processes both /// regular suggestion sets and file completion suggestions differently. + #[must_use] pub fn strip_typed_argument(&self, suggest: Suggest) -> Suggest { let typed = Self::get_typed_arguments(self); match suggest { @@ -223,11 +224,12 @@ impl ShellContext { /// This method collects all words in the shell context that start with a dash (`-`), /// which typically represent command-line flags or options. It returns a vector /// containing these flag strings, converted to owned `String` values. + #[must_use] pub fn get_typed_arguments(&self) -> HashSet<String> { self.all_words .iter() - .filter(|word| word.starts_with("-")) - .map(|word| word.to_string()) + .filter(|word| word.starts_with('-')) + .cloned() .collect() } } |
