From 71c5e27f8bf484bc745ac4bed55d917ec8947b5b Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 20 Aug 2024 08:48:19 -0500 Subject: [PATCH] fix(complete)!: Rename CustomCompleter to ValueCandidates --- clap_complete/src/engine/custom.rs | 10 +++++----- clap_complete/src/engine/mod.rs | 2 +- clap_complete/tests/testsuite/engine.rs | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/clap_complete/src/engine/custom.rs b/clap_complete/src/engine/custom.rs index 7813773b..20872960 100644 --- a/clap_complete/src/engine/custom.rs +++ b/clap_complete/src/engine/custom.rs @@ -5,7 +5,7 @@ use clap::builder::ArgExt; use super::CompletionCandidate; -/// Extend [`Arg`][clap::Arg] with a [`CustomCompleter`] +/// Extend [`Arg`][clap::Arg] with a [`ValueCandidates`] /// /// # Example /// @@ -23,13 +23,13 @@ use super::CompletionCandidate; /// } /// ``` #[derive(Clone)] -pub struct ArgValueCompleter(Arc); +pub struct ArgValueCompleter(Arc); impl ArgValueCompleter { /// Create a new `ArgValueCompleter` with a custom completer pub fn new(completer: C) -> Self where - C: CustomCompleter + 'static, + C: ValueCandidates + 'static, { Self(Arc::new(completer)) } @@ -53,14 +53,14 @@ impl ArgExt for ArgValueCompleter {} /// User-provided completion candidates for an [`Arg`][clap::Arg], see [`ArgValueCompleter`] /// /// This is useful when predefined value hints are not enough. -pub trait CustomCompleter: Send + Sync { +pub trait ValueCandidates: Send + Sync { /// All potential candidates for an argument. /// /// See [`CompletionCandidate`] for more information. fn candidates(&self) -> Vec; } -impl CustomCompleter for F +impl ValueCandidates for F where F: Fn() -> Vec + Send + Sync, { diff --git a/clap_complete/src/engine/mod.rs b/clap_complete/src/engine/mod.rs index c10cf57a..4cedd9a7 100644 --- a/clap_complete/src/engine/mod.rs +++ b/clap_complete/src/engine/mod.rs @@ -9,4 +9,4 @@ mod custom; pub use candidate::CompletionCandidate; pub use complete::complete; pub use custom::ArgValueCompleter; -pub use custom::CustomCompleter; +pub use custom::ValueCandidates; diff --git a/clap_complete/tests/testsuite/engine.rs b/clap_complete/tests/testsuite/engine.rs index fc991258..8c6cebe8 100644 --- a/clap_complete/tests/testsuite/engine.rs +++ b/clap_complete/tests/testsuite/engine.rs @@ -4,7 +4,7 @@ use std::fs; use std::path::Path; use clap::{builder::PossibleValue, Command}; -use clap_complete::engine::{ArgValueCompleter, CompletionCandidate, CustomCompleter}; +use clap_complete::engine::{ArgValueCompleter, CompletionCandidate, ValueCandidates}; use snapbox::assert_data_eq; macro_rules! complete { @@ -596,7 +596,7 @@ fn suggest_custom_arg_value() { #[derive(Debug)] struct MyCustomCompleter {} - impl CustomCompleter for MyCustomCompleter { + impl ValueCandidates for MyCustomCompleter { fn candidates(&self) -> Vec { vec![ CompletionCandidate::new("custom1"),