From 43fadfa22b1f28382338c892d91a6c388b5e540c Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Sun, 2 Aug 2026 12:11:47 +0800 Subject: feat(core): add batch methods to Suggest and update macro Add `add_suggest()` and `add_suggest_with_description()` methods to `Suggest` for ergonomic batch population of suggestion sets from collections of strings. Update the `suggest!` macro to use these new methods and accept expressions beyond string literals for suggestion items. --- mingling_core/src/comp/suggest.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'mingling_core/src/comp') diff --git a/mingling_core/src/comp/suggest.rs b/mingling_core/src/comp/suggest.rs index 88fa5fc..dda5026 100644 --- a/mingling_core/src/comp/suggest.rs +++ b/mingling_core/src/comp/suggest.rs @@ -56,6 +56,42 @@ impl Suggest { (suggest, _) => suggest, } } + + /// Adds multiple simple suggestions (without descriptions) to the `Suggest` set. + /// + /// Each item produced by the iterator is wrapped in a [`SuggestItem::Simple`] + /// variant and inserted into the underlying `BTreeSet`. + /// + /// # Arguments + /// + /// * `items` — A collection of suggestion strings to add. + pub fn add_suggest(&mut self, items: impl Into>) { + for item in items.into() { + self.insert(SuggestItem::Simple(item)); + } + } + + /// Adds multiple suggestions with a shared description to the `Suggest` set. + /// + /// Each item produced by the iterator is wrapped in a + /// [`SuggestItem::WithDescription`] variant using the provided description, + /// and inserted into the underlying `BTreeSet`. + /// + /// # Arguments + /// + /// * `items` — A collection of suggestion strings to add. + /// * `desc` — The description to attach to each suggestion. Must implement + /// `Into`. + pub fn add_suggest_with_description( + &mut self, + items: impl Into>, + desc: impl Into, + ) { + let desc_str = desc.into(); + for item in items.into() { + self.insert(SuggestItem::WithDescription(item, desc_str.clone())); + } + } } impl From for Suggest -- cgit