From 661ccc2d30f0e8ab4acecadebbe46fb5a39b6416 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 16 Aug 2024 09:37:09 -0500 Subject: [PATCH 1/2] feat(complete): Make Shells::builtins const --- clap_complete/src/dynamic/env/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clap_complete/src/dynamic/env/mod.rs b/clap_complete/src/dynamic/env/mod.rs index be736e759b5..eb5b28a8d27 100644 --- a/clap_complete/src/dynamic/env/mod.rs +++ b/clap_complete/src/dynamic/env/mod.rs @@ -232,7 +232,7 @@ pub struct Shells<'s>(pub &'s [&'s dyn EnvCompleter]); impl<'s> Shells<'s> { /// Select all of the built-in shells - pub fn builtins() -> Self { + pub const fn builtins() -> Self { Self(&[&Bash, &Elvish, &Fish, &Powershell, &Zsh]) } From f969bec2c006b3cbaad89cd093b8201eb98780ff Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 16 Aug 2024 09:38:40 -0500 Subject: [PATCH 2/2] feat(complete): Add Shells::iter Didn't add an `IntoIterator` because I didn't want to bother writing an opaque iterator type --- clap_complete/src/dynamic/env/mod.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/clap_complete/src/dynamic/env/mod.rs b/clap_complete/src/dynamic/env/mod.rs index eb5b28a8d27..a54e72b6295 100644 --- a/clap_complete/src/dynamic/env/mod.rs +++ b/clap_complete/src/dynamic/env/mod.rs @@ -245,6 +245,11 @@ impl<'s> Shells<'s> { pub fn names(&self) -> impl Iterator + 's { self.0.iter().map(|c| c.name()) } + + /// Iterate over [`EnvCompleter`]s + pub fn iter(&self) -> impl Iterator { + self.0.iter().copied() + } } /// Shell-integration for completions