Debian Codegraph @

crates/graph/src/parents_provider.rs

raw symbols SCIP
1 use craterust-analyzer cargo vcs-graph 3.6.0 crate/::{ParentMaprust-analyzer cargo vcs-graph 3.6.0 ParentMap#, Parentsrust-analyzer cargo vcs-graph 3.6.0 Parents#};
2 use rustc_hashrust-analyzer cargo rustc-hash 2.1.2 crate/::{FxHashMaprust-analyzer cargo rustc-hash 2.1.2 FxHashMap#, FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#};
3 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::{HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#, HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#};
4 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::hashrust-analyzer cargo std https://github.com/rust-lang/rust/library/std hash/::Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash#;
5 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::Mutexrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/Mutex#;
6
7 pub trait ParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/ParentsProvider#<K: PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq# + Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# + Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash#> {
8 fn get_parent_maprust-analyzer cargo vcs-graph 3.6.0 parents_provider/ParentsProvider#get_parent_map().(&self, keys: &HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<K>) -> ParentMaprust-analyzer cargo vcs-graph 3.6.0 ParentMap#<K>;
9 }
10
11 pub struct StackedParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/StackedParentsProvider#<K> {
12 parent_providersrust-analyzer cargo vcs-graph 3.6.0 parents_provider/StackedParentsProvider#parent_providers.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn ParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/ParentsProvider#<K>>>,
13 }
14
15 impl<K> StackedParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/StackedParentsProvider#<K> {
16 pub fn newrust-analyzer cargo vcs-graph 3.6.0 parents_provider/impl#[`StackedParentsProvider<K>`]new().(parent_providers: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn ParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/ParentsProvider#<K>>>) -> Selfrust-analyzer cargo vcs-graph 3.6.0 parents_provider/impl#[`StackedParentsProvider<K>`] {
17 StackedParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/StackedParentsProvider# { parent_providersrust-analyzer cargo vcs-graph 3.6.0 parents_provider/StackedParentsProvider#parent_providers. }
18 }
19 }
20
21 impl<K: Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash# + Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#> ParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/ParentsProvider#<K> for StackedParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/StackedParentsProvider#<K> {
22 fn get_parent_maprust-analyzer cargo vcs-graph 3.6.0 parents_provider/impl#[`StackedParentsProvider<K>`][`ParentsProvider<K>`]get_parent_map().(&self, keys: &HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<K>) -> ParentMaprust-analyzer cargo vcs-graph 3.6.0 ParentMap#<K> {
23 let mut found = ParentMaprust-analyzer cargo vcs-graph 3.6.0 ParentMap#::newrust-analyzer cargo vcs-graph 3.6.0 impl#[`ParentMap<K>`]new().();
24 let mut remaining = keys.clonerust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`][Clone]clone().();
25
26 for parent_provider in self.parent_providersrust-analyzer cargo vcs-graph 3.6.0 parents_provider/StackedParentsProvider#parent_providers..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() {
27 if remaining.is_emptyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]is_empty().() {
28 break;
29 }
30
31 let new_found = parent_provider.get_parent_maprust-analyzer cargo vcs-graph 3.6.0 parents_provider/ParentsProvider#get_parent_map().(&remaining);
32 for k in new_found.keysrust-analyzer cargo vcs-graph 3.6.0 impl#[`ParentMap<K>`]keys().() {
33 remaining.removerust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]remove().(k);
34 }
35 found.extendrust-analyzer cargo vcs-graph 3.6.0 impl#[`ParentMap<K>`]extend().(new_found);
36 }
37
38 found
39 }
40 }
41
42 pub struct DictParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/DictParentsProvider#<K: Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash# + Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#>(ParentMaprust-analyzer cargo vcs-graph 3.6.0 ParentMap#<K>);
43
44 impl<K: Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash# + Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#> Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<ParentMaprust-analyzer cargo vcs-graph 3.6.0 ParentMap#<K>> for DictParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/DictParentsProvider#<K> {
45 fn fromrust-analyzer cargo vcs-graph 3.6.0 parents_provider/impl#[`DictParentsProvider<K>`][`From<ParentMap<K>>`]from().(parent_map: ParentMaprust-analyzer cargo vcs-graph 3.6.0 ParentMap#<K>) -> Selfrust-analyzer cargo vcs-graph 3.6.0 parents_provider/impl#[`DictParentsProvider<K>`][`From<ParentMap<K>>`] {
46 DictParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/DictParentsProvider#(parent_map)
47 }
48 }
49
50 impl<K: Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash# + Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#> Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<K, Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<K>>> for DictParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/DictParentsProvider#<K> {
51 fn fromrust-analyzer cargo vcs-graph 3.6.0 parents_provider/impl#[`DictParentsProvider<K>`][`From<HashMap<K, Vec<K>>>`]from().(parent_map: HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<K, Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<K>>) -> Selfrust-analyzer cargo vcs-graph 3.6.0 parents_provider/impl#[`DictParentsProvider<K>`][`From<HashMap<K, Vec<K>>>`] {
52 DictParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/DictParentsProvider#::newrust-analyzer cargo vcs-graph 3.6.0 parents_provider/impl#[`DictParentsProvider<K>`]new().(ParentMaprust-analyzer cargo vcs-graph 3.6.0 ParentMap#(
53 parent_map
54 .into_iterrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][IntoIterator]into_iter().()
55 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(k, v)| (k, Parentsrust-analyzer cargo vcs-graph 3.6.0 Parents#::Knownrust-analyzer cargo vcs-graph 3.6.0 Parents#Known#(v)))
56 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(),
57 ))
58 }
59 }
60
61 impl<K: Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash# + Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#> DictParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/DictParentsProvider#<K> {
62 pub fn newrust-analyzer cargo vcs-graph 3.6.0 parents_provider/impl#[`DictParentsProvider<K>`]new().(parent_map: ParentMaprust-analyzer cargo vcs-graph 3.6.0 ParentMap#<K>) -> Selfrust-analyzer cargo vcs-graph 3.6.0 parents_provider/impl#[`DictParentsProvider<K>`] {
63 DictParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/DictParentsProvider#(parent_map)
64 }
65 }
66
67 impl<K: Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash# + Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#> ParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/ParentsProvider#<K> for DictParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/DictParentsProvider#<K> {
68 fn get_parent_maprust-analyzer cargo vcs-graph 3.6.0 parents_provider/impl#[`DictParentsProvider<K>`][`ParentsProvider<K>`]get_parent_map().(&self, keys: &HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<K>) -> ParentMaprust-analyzer cargo vcs-graph 3.6.0 ParentMap#<K> {
69 ParentMaprust-analyzer cargo vcs-graph 3.6.0 ParentMap#(
70 keys.iterrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]iter().()
71 .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|k| self.0rust-analyzer cargo vcs-graph 3.6.0 parents_provider/DictParentsProvider#0..get_key_valuerust-analyzer cargo vcs-graph 3.6.0 impl#[`ParentMap<K>`]get_key_value().(k))
72 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(k, v)| (k.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().(), v.clonerust-analyzer cargo vcs-graph 3.6.0 impl#[`Parents<K>`][Clone]clone().()))
73 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(),
74 )
75 }
76 }
77
78 /// A parents provider which caches its lookups.
79 ///
80 /// Wraps an inner `ParentsProvider` and memoizes every `(key, parents)`
81 /// pair it returns. When cache-misses-tracking is enabled, keys that were
82 /// requested but not present in the inner provider are also remembered so
83 /// we don't re-request them.
84 ///
85 /// The cache can be disabled and re-enabled at runtime; disabling clears
86 /// the cache entirely.
87 pub struct CachingParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/CachingParentsProvider#<K: Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash# + Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, P: ParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/ParentsProvider#<K>> {
88 innerrust-analyzer cargo vcs-graph 3.6.0 parents_provider/CachingParentsProvider#inner.: P,
89 // Interior mutability so `get_parent_map(&self, ...)` can populate the
90 // cache. The whole provider is still Sync (via Mutex) which matches the
91 // base trait's `&self` contract.
92 staterust-analyzer cargo vcs-graph 3.6.0 parents_provider/CachingParentsProvider#state.: Mutexrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/Mutex#<CacheStaterust-analyzer cargo vcs-graph 3.6.0 parents_provider/CacheState#<K>>,
93 }
94
95 struct CacheStaterust-analyzer cargo vcs-graph 3.6.0 parents_provider/CacheState#<K: Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash# + Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#> {
96 /// None when the cache is disabled, Some when enabled.
97 cacherust-analyzer cargo vcs-graph 3.6.0 parents_provider/CacheState#cache.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<FxHashMaprust-analyzer cargo rustc-hash 2.1.2 FxHashMap#<K, Parentsrust-analyzer cargo vcs-graph 3.6.0 Parents#<K>>>,
98 /// Keys known to be missing from the inner provider. Only populated
99 /// when `cache_misses` is true.
100 missing_keysrust-analyzer cargo vcs-graph 3.6.0 parents_provider/CacheState#missing_keys.: FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K>,
101 /// Whether to remember keys that aren't in the inner provider.
102 cache_missesrust-analyzer cargo vcs-graph 3.6.0 parents_provider/CacheState#cache_misses.: bool,
103 }
104
105 impl<K: Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash# + Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, P: ParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/ParentsProvider#<K>> CachingParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/CachingParentsProvider#<K, P> {
106 /// Create a caching wrapper around `inner`. The cache is enabled by
107 /// default with cache-misses tracking on.
108 pub fn newrust-analyzer cargo vcs-graph 3.6.0 parents_provider/impl#[`CachingParentsProvider<K, P>`]new().(inner: P) -> Selfrust-analyzer cargo vcs-graph 3.6.0 parents_provider/impl#[`CachingParentsProvider<K, P>`] {
109 CachingParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/CachingParentsProvider# {
110 innerrust-analyzer cargo vcs-graph 3.6.0 parents_provider/CachingParentsProvider#inner.,
111 staterust-analyzer cargo vcs-graph 3.6.0 parents_provider/CachingParentsProvider#state.: Mutexrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/Mutex#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`Mutex<T>`]new().(CacheStaterust-analyzer cargo vcs-graph 3.6.0 parents_provider/CacheState# {
112 cacherust-analyzer cargo vcs-graph 3.6.0 parents_provider/CacheState#cache.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(FxHashMaprust-analyzer cargo rustc-hash 2.1.2 FxHashMap#::defaultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S>`][Default]default().()),
113 missing_keysrust-analyzer cargo vcs-graph 3.6.0 parents_provider/CacheState#missing_keys.: FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#::defaultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S>`][Default]default().(),
114 cache_missesrust-analyzer cargo vcs-graph 3.6.0 parents_provider/CacheState#cache_misses.: true,
115 }),
116 }
117 }
118
119 /// Enable the cache. Matches Python's semantics: calling this when the
120 /// cache is already enabled is an error. `cache_misses` controls
121 /// whether missing keys are remembered between calls.
122 pub fn enable_cacherust-analyzer cargo vcs-graph 3.6.0 parents_provider/impl#[`CachingParentsProvider<K, P>`]enable_cache().(&self, cache_misses: bool) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), &'static str> {
123 let mut state = self.staterust-analyzer cargo vcs-graph 3.6.0 parents_provider/CachingParentsProvider#state..lockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`Mutex<T>`]lock().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
124 if state.cacherust-analyzer cargo vcs-graph 3.6.0 parents_provider/CacheState#cache..is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() {
125 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#("Cache enabled when already enabled.");
126 }
127 state.cacherust-analyzer cargo vcs-graph 3.6.0 parents_provider/CacheState#cache. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(FxHashMaprust-analyzer cargo rustc-hash 2.1.2 FxHashMap#::defaultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S>`][Default]default().());
128 state.cache_missesrust-analyzer cargo vcs-graph 3.6.0 parents_provider/CacheState#cache_misses. = cache_misses;
129 state.missing_keysrust-analyzer cargo vcs-graph 3.6.0 parents_provider/CacheState#missing_keys. = FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#::defaultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S>`][Default]default().();
130 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
131 }
132
133 /// Disable and clear the cache.
134 pub fn disable_cacherust-analyzer cargo vcs-graph 3.6.0 parents_provider/impl#[`CachingParentsProvider<K, P>`]disable_cache().(&self) {
135 let mut state = self.staterust-analyzer cargo vcs-graph 3.6.0 parents_provider/CachingParentsProvider#state..lockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`Mutex<T>`]lock().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
136 state.cacherust-analyzer cargo vcs-graph 3.6.0 parents_provider/CacheState#cache. = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
137 state.cache_missesrust-analyzer cargo vcs-graph 3.6.0 parents_provider/CacheState#cache_misses. = false;
138 state.missing_keysrust-analyzer cargo vcs-graph 3.6.0 parents_provider/CacheState#missing_keys. = FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#::defaultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S>`][Default]default().();
139 }
140
141 /// Return a snapshot of the current cache, or `None` if disabled.
142 pub fn get_cached_maprust-analyzer cargo vcs-graph 3.6.0 parents_provider/impl#[`CachingParentsProvider<K, P>`]get_cached_map().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<FxHashMaprust-analyzer cargo rustc-hash 2.1.2 FxHashMap#<K, Parentsrust-analyzer cargo vcs-graph 3.6.0 Parents#<K>>> {
143 let state = self.staterust-analyzer cargo vcs-graph 3.6.0 parents_provider/CachingParentsProvider#state..lockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`Mutex<T>`]lock().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
144 state.cacherust-analyzer cargo vcs-graph 3.6.0 parents_provider/CacheState#cache..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Clone]clone().()
145 }
146
147 /// Return entries from the cache without consulting the inner provider.
148 pub fn get_cached_parent_maprust-analyzer cargo vcs-graph 3.6.0 parents_provider/impl#[`CachingParentsProvider<K, P>`]get_cached_parent_map().(&self, keys: &HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<K>) -> ParentMaprust-analyzer cargo vcs-graph 3.6.0 ParentMap#<K> {
149 let state = self.staterust-analyzer cargo vcs-graph 3.6.0 parents_provider/CachingParentsProvider#state..lockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`Mutex<T>`]lock().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
150 let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(cache) = state.cacherust-analyzer cargo vcs-graph 3.6.0 parents_provider/CacheState#cache..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().() else {
151 return ParentMaprust-analyzer cargo vcs-graph 3.6.0 ParentMap#::newrust-analyzer cargo vcs-graph 3.6.0 impl#[`ParentMap<K>`]new().();
152 };
153 ParentMaprust-analyzer cargo vcs-graph 3.6.0 ParentMap#(
154 keys.iterrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]iter().()
155 .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|k| cache.get_key_valuerust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get_key_value().(k))
156 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(k, v)| (k.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().(), v.clonerust-analyzer cargo vcs-graph 3.6.0 impl#[`Parents<K>`][Clone]clone().()))
157 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(),
158 )
159 }
160
161 /// Note that `key` was missing from the inner provider.
162 pub fn note_missing_keyrust-analyzer cargo vcs-graph 3.6.0 parents_provider/impl#[`CachingParentsProvider<K, P>`]note_missing_key().(&self, key: K) {
163 let mut state = self.staterust-analyzer cargo vcs-graph 3.6.0 parents_provider/CachingParentsProvider#state..lockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`Mutex<T>`]lock().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
164 if state.cache_missesrust-analyzer cargo vcs-graph 3.6.0 parents_provider/CacheState#cache_misses. {
165 state.missing_keysrust-analyzer cargo vcs-graph 3.6.0 parents_provider/CacheState#missing_keys..insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]insert().(key);
166 }
167 }
168
169 /// Snapshot of the missing-keys set.
170 pub fn missing_keysrust-analyzer cargo vcs-graph 3.6.0 parents_provider/impl#[`CachingParentsProvider<K, P>`]missing_keys().(&self) -> FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<K> {
171 self.staterust-analyzer cargo vcs-graph 3.6.0 parents_provider/CachingParentsProvider#state..lockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`Mutex<T>`]lock().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().missing_keysrust-analyzer cargo vcs-graph 3.6.0 parents_provider/CacheState#missing_keys..clonerust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`][Clone]clone().()
172 }
173
174 /// Replace the missing-keys set wholesale. Used by the Python bindings to
175 /// sync external mutations of the exposed Python set back into Rust state.
176 pub fn set_missing_keysrust-analyzer cargo vcs-graph 3.6.0 parents_provider/impl#[`CachingParentsProvider<K, P>`]set_missing_keys().<I: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = K>>(&self, keys: I) {
177 let mut state = self.staterust-analyzer cargo vcs-graph 3.6.0 parents_provider/CachingParentsProvider#state..lockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`Mutex<T>`]lock().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
178 state.missing_keysrust-analyzer cargo vcs-graph 3.6.0 parents_provider/CacheState#missing_keys. = keys.into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#into_iter().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
179 }
180
181 /// Borrow the inner provider.
182 pub fn innerrust-analyzer cargo vcs-graph 3.6.0 parents_provider/impl#[`CachingParentsProvider<K, P>`]inner().(&self) -> &P {
183 &self.innerrust-analyzer cargo vcs-graph 3.6.0 parents_provider/CachingParentsProvider#inner.
184 }
185 }
186
187 impl<K: Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash# + Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, P: ParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/ParentsProvider#<K>> ParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/ParentsProvider#<K>
188 for CachingParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/CachingParentsProvider#<K, P>
189 {
190 fn get_parent_maprust-analyzer cargo vcs-graph 3.6.0 parents_provider/impl#[`CachingParentsProvider<K, P>`][`ParentsProvider<K>`]get_parent_map().(&self, keys: &HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<K>) -> ParentMaprust-analyzer cargo vcs-graph 3.6.0 ParentMap#<K> {
191 // Fast path: cache disabled — delegate straight to inner.
192 {
193 let state = self.staterust-analyzer cargo vcs-graph 3.6.0 parents_provider/CachingParentsProvider#state..lockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`Mutex<T>`]lock().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
194 if state.cacherust-analyzer cargo vcs-graph 3.6.0 parents_provider/CacheState#cache..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() {
195 droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/drop().(state);
196 // Note: Python filters the response to only the requested
197 // keys with non-None values; we do the same by filtering
198 // known parents below.
199 let pm = self.innerrust-analyzer cargo vcs-graph 3.6.0 parents_provider/CachingParentsProvider#inner..get_parent_maprust-analyzer cargo vcs-graph 3.6.0 parents_provider/ParentsProvider#get_parent_map().(keys);
200 let mut result = ParentMaprust-analyzer cargo vcs-graph 3.6.0 ParentMap#::newrust-analyzer cargo vcs-graph 3.6.0 impl#[`ParentMap<K>`]new().();
201 for k in keys {
202 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v) = pm.getrust-analyzer cargo vcs-graph 3.6.0 impl#[`ParentMap<K>`]get().(k) {
203 if matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(v, Parentsrust-analyzer cargo vcs-graph 3.6.0 Parents#::Knownrust-analyzer cargo vcs-graph 3.6.0 Parents#Known#(_)) {
204 result.insertrust-analyzer cargo vcs-graph 3.6.0 impl#[`ParentMap<K>`]insert().(k.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().(), v.clonerust-analyzer cargo vcs-graph 3.6.0 impl#[`Parents<K>`][Clone]clone().());
205 }
206 }
207 }
208 return result;
209 }
210 }
211
212 // Determine which keys we still need to fetch from the inner
213 // provider (not in cache and not known-missing).
214 let needed: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<K> = {
215 let state = self.staterust-analyzer cargo vcs-graph 3.6.0 parents_provider/CachingParentsProvider#state..lockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`Mutex<T>`]lock().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
216 let cache = state.cacherust-analyzer cargo vcs-graph 3.6.0 parents_provider/CacheState#cache..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
217 keys.iterrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]iter().()
218 .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|k| !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().cache.contains_keyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]contains_key().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().k) && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().state.missing_keysrust-analyzer cargo vcs-graph 3.6.0 parents_provider/CacheState#missing_keys..containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().k))
219 .clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().()
220 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().()
221 };
222
223 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().needed.is_emptyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]is_empty().() {
224 let fetched = self.innerrust-analyzer cargo vcs-graph 3.6.0 parents_provider/CachingParentsProvider#inner..get_parent_maprust-analyzer cargo vcs-graph 3.6.0 parents_provider/ParentsProvider#get_parent_map().(&needed);
225 let mut state = self.staterust-analyzer cargo vcs-graph 3.6.0 parents_provider/CachingParentsProvider#state..lockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`Mutex<T>`]lock().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
226 let cache = state.cacherust-analyzer cargo vcs-graph 3.6.0 parents_provider/CacheState#cache..as_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_mut().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
227 for (k, v) in fetched.iterrust-analyzer cargo vcs-graph 3.6.0 impl#[`ParentMap<K>`]iter().() {
228 cache.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().(k.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().(), v.clonerust-analyzer cargo vcs-graph 3.6.0 impl#[`Parents<K>`][Clone]clone().());
229 }
230 if state.cache_missesrust-analyzer cargo vcs-graph 3.6.0 parents_provider/CacheState#cache_misses. {
231 for k in &needed {
232 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().fetched.contains_keyrust-analyzer cargo vcs-graph 3.6.0 impl#[`ParentMap<K>`]contains_key().(k) {
233 state.missing_keysrust-analyzer cargo vcs-graph 3.6.0 parents_provider/CacheState#missing_keys..insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]insert().(k.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().());
234 }
235 }
236 }
237 }
238
239 // Build the response from the cache, filtering out ghosts/None the
240 // same way Python does.
241 let state = self.staterust-analyzer cargo vcs-graph 3.6.0 parents_provider/CachingParentsProvider#state..lockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`Mutex<T>`]lock().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
242 let cache = state.cacherust-analyzer cargo vcs-graph 3.6.0 parents_provider/CacheState#cache..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
243 let mut result = ParentMaprust-analyzer cargo vcs-graph 3.6.0 ParentMap#::newrust-analyzer cargo vcs-graph 3.6.0 impl#[`ParentMap<K>`]new().();
244 for k in keys {
245 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v) = cache.getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(k) {
246 if matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(v, Parentsrust-analyzer cargo vcs-graph 3.6.0 Parents#::Knownrust-analyzer cargo vcs-graph 3.6.0 Parents#Known#(_)) {
247 result.insertrust-analyzer cargo vcs-graph 3.6.0 impl#[`ParentMap<K>`]insert().(k.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().(), v.clonerust-analyzer cargo vcs-graph 3.6.0 impl#[`Parents<K>`][Clone]clone().());
248 }
249 }
250 }
251 result
252 }
253 }
254
255 #[cfg(test)]
256 mod testsrust-analyzer cargo vcs-graph 3.6.0 parents_provider/tests/ {
257 use superrust-analyzer cargo vcs-graph 3.6.0 parents_provider/::*;
258 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/::RefCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/RefCell#;
259
260 /// A ParentsProvider wrapper that counts how many distinct keys were
261 /// requested across all calls to `get_parent_map`. Used to verify the
262 /// caching wrapper avoids redundant lookups.
263 struct CountingProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/tests/CountingProvider#<K: Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash# + Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, P: ParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/ParentsProvider#<K>> {
264 innerrust-analyzer cargo vcs-graph 3.6.0 parents_provider/tests/CountingProvider#inner.: P,
265 requestedrust-analyzer cargo vcs-graph 3.6.0 parents_provider/tests/CountingProvider#requested.: RefCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/RefCell#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<K>>,
266 }
267
268 impl<K: Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash# + Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, P: ParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/ParentsProvider#<K>> CountingProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/tests/CountingProvider#<K, P> {
269 fn newrust-analyzer cargo vcs-graph 3.6.0 parents_provider/tests/impl#[`CountingProvider<K, P>`]new().(inner: P) -> Selfrust-analyzer cargo vcs-graph 3.6.0 parents_provider/tests/impl#[`CountingProvider<K, P>`] {
270 CountingProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/tests/CountingProvider# {
271 innerrust-analyzer cargo vcs-graph 3.6.0 parents_provider/tests/CountingProvider#inner.,
272 requestedrust-analyzer cargo vcs-graph 3.6.0 parents_provider/tests/CountingProvider#requested.: RefCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/RefCell#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]new().(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().()),
273 }
274 }
275 }
276
277 impl<K: Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash# + Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, P: ParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/ParentsProvider#<K>> ParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/ParentsProvider#<K> for CountingProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/tests/CountingProvider#<K, P> {
278 fn get_parent_maprust-analyzer cargo vcs-graph 3.6.0 parents_provider/tests/impl#[`CountingProvider<K, P>`][`ParentsProvider<K>`]get_parent_map().(&self, keys: &HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<K>) -> ParentMaprust-analyzer cargo vcs-graph 3.6.0 ParentMap#<K> {
279 self.requestedrust-analyzer cargo vcs-graph 3.6.0 parents_provider/tests/CountingProvider#requested..borrow_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow_mut().().extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().(keys.iterrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]iter().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().());
280 self.innerrust-analyzer cargo vcs-graph 3.6.0 parents_provider/tests/CountingProvider#inner..get_parent_maprust-analyzer cargo vcs-graph 3.6.0 parents_provider/ParentsProvider#get_parent_map().(keys)
281 }
282 }
283
284 fn dictrust-analyzer cargo vcs-graph 3.6.0 parents_provider/tests/dict().(edges: &[(&'static str, &[&'static str])]) -> DictParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/DictParentsProvider#<&'static str> {
285 let map: HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<&'static str, Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<&'static str>> =
286 edges.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(k, ps)| (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().k, ps.to_vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]to_vec().())).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
287 DictParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/DictParentsProvider#::fromrust-analyzer cargo vcs-graph 3.6.0 parents_provider/impl#[`DictParentsProvider<K>`][`From<HashMap<K, Vec<K>>>`]from().(map)
288 }
289
290 fn queryrust-analyzer cargo vcs-graph 3.6.0 parents_provider/tests/query().(
291 cp: &CachingParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/CachingParentsProvider#<
292 &'static str,
293 CountingProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/tests/CountingProvider#<&'static str, DictParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/DictParentsProvider#<&'static str>>,
294 >,
295 keys: &[&'static str],
296 ) -> ParentMaprust-analyzer cargo vcs-graph 3.6.0 ParentMap#<&'static str> {
297 let hs: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<&'static str> = keys.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().copiedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#copied().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
298 cp.get_parent_maprust-analyzer cargo vcs-graph 3.6.0 parents_provider/impl#[`CachingParentsProvider<K, P>`][`ParentsProvider<K>`]get_parent_map().(&hs)
299 }
300
301 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
302 fn caching_returns_known_parentsrust-analyzer cargo vcs-graph 3.6.0 parents_provider/tests/caching_returns_known_parents().() {
303 let inner = CountingProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/tests/CountingProvider#::newrust-analyzer cargo vcs-graph 3.6.0 parents_provider/tests/impl#[`CountingProvider<K, P>`]new().(dictrust-analyzer cargo vcs-graph 3.6.0 parents_provider/tests/dict().(&[("a", &[]), ("b", &["a"])]));
304 let cp = CachingParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/CachingParentsProvider#::newrust-analyzer cargo vcs-graph 3.6.0 parents_provider/impl#[`CachingParentsProvider<K, P>`]new().(inner);
305 let pm = queryrust-analyzer cargo vcs-graph 3.6.0 parents_provider/tests/query().(&cp, &["a", "b"]);
306 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(pm.getrust-analyzer cargo vcs-graph 3.6.0 impl#[`ParentMap<K>`]get().(&"a"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&Parentsrust-analyzer cargo vcs-graph 3.6.0 Parents#::Knownrust-analyzer cargo vcs-graph 3.6.0 Parents#Known#(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![])));
307 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(pm.getrust-analyzer cargo vcs-graph 3.6.0 impl#[`ParentMap<K>`]get().(&"b"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&Parentsrust-analyzer cargo vcs-graph 3.6.0 Parents#::Knownrust-analyzer cargo vcs-graph 3.6.0 Parents#Known#(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["a"])));
308 }
309
310 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
311 fn caching_avoids_refetching_known_keysrust-analyzer cargo vcs-graph 3.6.0 parents_provider/tests/caching_avoids_refetching_known_keys().() {
312 let inner = CountingProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/tests/CountingProvider#::newrust-analyzer cargo vcs-graph 3.6.0 parents_provider/tests/impl#[`CountingProvider<K, P>`]new().(dictrust-analyzer cargo vcs-graph 3.6.0 parents_provider/tests/dict().(&[("a", &[]), ("b", &["a"])]));
313 let cp = CachingParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/CachingParentsProvider#::newrust-analyzer cargo vcs-graph 3.6.0 parents_provider/impl#[`CachingParentsProvider<K, P>`]new().(inner);
314 queryrust-analyzer cargo vcs-graph 3.6.0 parents_provider/tests/query().(&cp, &["a", "b"]);
315 queryrust-analyzer cargo vcs-graph 3.6.0 parents_provider/tests/query().(&cp, &["a", "b"]);
316 // Only one round trip for each key.
317 let requested = cp.innerrust-analyzer cargo vcs-graph 3.6.0 parents_provider/impl#[`CachingParentsProvider<K, P>`]inner().().requestedrust-analyzer cargo vcs-graph 3.6.0 parents_provider/tests/CountingProvider#requested..borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow().();
318 let mut seen = FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#::defaultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S>`][Default]default().();
319 for k in requested.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() {
320 seen.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]insert().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().k);
321 }
322 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(seen, ["a", "b"].into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/iter/impl#[`[T; N]`][IntoIterator]into_iter().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<FxHashSetrust-analyzer cargo rustc-hash 2.1.2 FxHashSet#<_>>());
323 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(requested.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 2);
324 }
325
326 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
327 fn caching_remembers_missing_keysrust-analyzer cargo vcs-graph 3.6.0 parents_provider/tests/caching_remembers_missing_keys().() {
328 let inner = CountingProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/tests/CountingProvider#::newrust-analyzer cargo vcs-graph 3.6.0 parents_provider/tests/impl#[`CountingProvider<K, P>`]new().(dictrust-analyzer cargo vcs-graph 3.6.0 parents_provider/tests/dict().(&[("a", &[])]));
329 let cp = CachingParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/CachingParentsProvider#::newrust-analyzer cargo vcs-graph 3.6.0 parents_provider/impl#[`CachingParentsProvider<K, P>`]new().(inner);
330 queryrust-analyzer cargo vcs-graph 3.6.0 parents_provider/tests/query().(&cp, &["a", "missing"]);
331 queryrust-analyzer cargo vcs-graph 3.6.0 parents_provider/tests/query().(&cp, &["missing"]);
332 // "missing" should have been requested exactly once.
333 let requested = cp.innerrust-analyzer cargo vcs-graph 3.6.0 parents_provider/impl#[`CachingParentsProvider<K, P>`]inner().().requestedrust-analyzer cargo vcs-graph 3.6.0 parents_provider/tests/CountingProvider#requested..borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow().();
334 let count = requested.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|k| *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().k rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."missing").countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter/impl#[`Filter<I, P>`][Iterator]count().();
335 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(count, 1);
336 }
337
338 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
339 fn disable_cache_clears_staterust-analyzer cargo vcs-graph 3.6.0 parents_provider/tests/disable_cache_clears_state().() {
340 let inner = CountingProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/tests/CountingProvider#::newrust-analyzer cargo vcs-graph 3.6.0 parents_provider/tests/impl#[`CountingProvider<K, P>`]new().(dictrust-analyzer cargo vcs-graph 3.6.0 parents_provider/tests/dict().(&[("a", &[])]));
341 let cp = CachingParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/CachingParentsProvider#::newrust-analyzer cargo vcs-graph 3.6.0 parents_provider/impl#[`CachingParentsProvider<K, P>`]new().(inner);
342 queryrust-analyzer cargo vcs-graph 3.6.0 parents_provider/tests/query().(&cp, &["a"]);
343 cp.disable_cacherust-analyzer cargo vcs-graph 3.6.0 parents_provider/impl#[`CachingParentsProvider<K, P>`]disable_cache().();
344 queryrust-analyzer cargo vcs-graph 3.6.0 parents_provider/tests/query().(&cp, &["a"]);
345 // With the cache disabled, every call hits the inner provider.
346 let requested = cp.innerrust-analyzer cargo vcs-graph 3.6.0 parents_provider/impl#[`CachingParentsProvider<K, P>`]inner().().requestedrust-analyzer cargo vcs-graph 3.6.0 parents_provider/tests/CountingProvider#requested..borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow().();
347 let count = requested.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|k| *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().k rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."a").countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter/impl#[`Filter<I, P>`][Iterator]count().();
348 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(count, 2);
349 }
350
351 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
352 fn enable_while_enabled_errorsrust-analyzer cargo vcs-graph 3.6.0 parents_provider/tests/enable_while_enabled_errors().() {
353 let cp = CachingParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/CachingParentsProvider#::newrust-analyzer cargo vcs-graph 3.6.0 parents_provider/impl#[`CachingParentsProvider<K, P>`]new().(dictrust-analyzer cargo vcs-graph 3.6.0 parents_provider/tests/dict().(&[("a", &[])]));
354 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(cp.enable_cacherust-analyzer cargo vcs-graph 3.6.0 parents_provider/impl#[`CachingParentsProvider<K, P>`]enable_cache().(true).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
355 }
356
357 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
358 fn reenabling_after_disable_worksrust-analyzer cargo vcs-graph 3.6.0 parents_provider/tests/reenabling_after_disable_works().() {
359 let cp = CachingParentsProviderrust-analyzer cargo vcs-graph 3.6.0 parents_provider/CachingParentsProvider#::newrust-analyzer cargo vcs-graph 3.6.0 parents_provider/impl#[`CachingParentsProvider<K, P>`]new().(dictrust-analyzer cargo vcs-graph 3.6.0 parents_provider/tests/dict().(&[("a", &[])]));
360 cp.disable_cacherust-analyzer cargo vcs-graph 3.6.0 parents_provider/impl#[`CachingParentsProvider<K, P>`]disable_cache().();
361 cp.enable_cacherust-analyzer cargo vcs-graph 3.6.0 parents_provider/impl#[`CachingParentsProvider<K, P>`]enable_cache().(true).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
362 let hs: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<&'static str> = ["a"].into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/iter/impl#[`[T; N]`][IntoIterator]into_iter().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
363 let pm = cp.get_parent_maprust-analyzer cargo vcs-graph 3.6.0 parents_provider/impl#[`CachingParentsProvider<K, P>`][`ParentsProvider<K>`]get_parent_map().(&hs);
364 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(pm.getrust-analyzer cargo vcs-graph 3.6.0 impl#[`ParentMap<K>`]get().(&"a"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&Parentsrust-analyzer cargo vcs-graph 3.6.0 Parents#::Knownrust-analyzer cargo vcs-graph 3.6.0 Parents#Known#(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![])));
365 }
366 }