diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-08-02 12:11:47 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-08-02 12:11:47 +0800 |
| commit | 43fadfa22b1f28382338c892d91a6c388b5e540c (patch) | |
| tree | fb986e1d4fa65801a8ced895e43c135921328cad /mingling_core/src/comp | |
| parent | 0f9ca0745e3e80c751404f45cb2b97d4d14c97d3 (diff) | |
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.
Diffstat (limited to 'mingling_core/src/comp')
| -rw-r--r-- | mingling_core/src/comp/suggest.rs | 36 |
1 files changed, 36 insertions, 0 deletions
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<Vec<String>>) { + 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<String>`. + pub fn add_suggest_with_description( + &mut self, + items: impl Into<Vec<String>>, + desc: impl Into<String>, + ) { + let desc_str = desc.into(); + for item in items.into() { + self.insert(SuggestItem::WithDescription(item, desc_str.clone())); + } + } } impl<T> From<T> for Suggest |
