1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//! Iterator extension that scores [`WeightedEntry`] streams against a
//! query, attaching combined `priority × relevance` scores and filtering
//! non-matches.
//!
//! Generic over `Item: AsRef<WeightedEntry>`, so the same trait covers:
//!
//! - owned iterators yielding [`WeightedEntry`] (via the reflexive
//! `AsRef<WeightedEntry>` impl on the type itself);
//! - borrowed iterators yielding `&WeightedEntry` (via std's blanket
//! `impl<T: AsRef<U>> AsRef<U> for &T`);
//! - any user wrapper that implements `AsRef<WeightedEntry>` — e.g. a
//! launcher's `LauncherEntry { weighted: WeightedEntry, … }` simply
//! adds `impl AsRef<WeightedEntry> for LauncherEntry { … }` and
//! gets `.score(q)` / `.sorted_by_score(q)` for free.
//!
//! Two methods on the trait:
//!
//! - [`score`](WeightedEntryIteratorExt::score) — lazy, returns
//! `Iterator<Item = (T, f32)>` filtered to matches. Compose with
//! `take`, `filter`, etc. before collecting.
//! - [`sorted_by_score`](WeightedEntryIteratorExt::sorted_by_score) —
//! eager, returns `Vec<T>` sorted highest-score-first (scores dropped
//! after sorting). The one-liner for "give me the ranked list."
//!
//! ```no_run
//! use wintheon::file::Priority;
//! use wintheon::gather::{Gatherer, WeightedEntryIteratorExt};
//!
//! let gatherer = Gatherer::new().with_start_menu(Priority(1.5));
//! let top = gatherer
//! .scan()
//! .filter_map(|r| r.ok())
//! .sorted_by_score("chrome");
//! for w in top.iter().take(10) {
//! println!("{}", w.entry.display_name());
//! }
//! ```
use Cow;
use crateWeightedEntry;
/// Adds `.score(query)` and `.sorted_by_score(query)` to any iterator
/// whose items can be viewed as a [`WeightedEntry`]. Bring the trait
/// into scope (`use wintheon::gather::WeightedEntryIteratorExt;`) to
/// use the methods.