| 1 | 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/::Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#; |
| 2 | |
| 3 | use fluent_urirust-analyzer cargo fluent-uri 0.4.1 crate/::Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#; |
| 4 | use hashbrownrust-analyzer cargo hashbrown 0.16.1 crate/::hash_maprust-analyzer cargo hashbrown 0.16.1 hash_map/::{EntryRefrust-analyzer cargo hashbrown 0.16.1 map/EntryRef#, HashMaprust-analyzer cargo hashbrown 0.16.1 map/HashMap#}; |
| 5 | use parking_lotrust-analyzer cargo parking_lot 0.12.5 crate/::{RwLockrust-analyzer cargo parking_lot 0.12.5 rwlock/RwLock#, RwLockUpgradableReadGuardrust-analyzer cargo parking_lot 0.12.5 rwlock/RwLockUpgradableReadGuard#}; |
| 6 | |
| 7 | use craterust-analyzer cargo referencing 0.37.4 crate/::{urirust-analyzer cargo referencing 0.37.4 uri/, Errorrust-analyzer cargo referencing 0.37.4 error/Error#}; |
| 8 | |
| 9 | type CacheBucketrust-analyzer cargo referencing 0.37.4 cache/CacheBucket# = HashMaprust-analyzer cargo hashbrown 0.16.1 map/HashMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>>; |
| 10 | type CacheMaprust-analyzer cargo referencing 0.37.4 cache/CacheMap# = HashMaprust-analyzer cargo hashbrown 0.16.1 map/HashMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, CacheBucketrust-analyzer cargo referencing 0.37.4 cache/CacheBucket#>; |
| 11 | |
| 12 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)] |
| 13 | pub(craterust-analyzer cargo referencing 0.37.4 crate/) struct UriCacherust-analyzer cargo referencing 0.37.4 cache/UriCache# { |
| 14 | cacherust-analyzer cargo referencing 0.37.4 cache/UriCache#cache.: CacheMaprust-analyzer cargo referencing 0.37.4 cache/CacheMap#, |
| 15 | } |
| 16 | |
| 17 | impl UriCacherust-analyzer cargo referencing 0.37.4 cache/UriCache# { |
| 18 | pub(craterust-analyzer cargo referencing 0.37.4 crate/) fn newrust-analyzer cargo referencing 0.37.4 cache/impl#[UriCache]new().() -> Selfrust-analyzer cargo referencing 0.37.4 cache/impl#[UriCache] { |
| 19 | Selfrust-analyzer cargo referencing 0.37.4 cache/impl#[UriCache] { |
| 20 | cacherust-analyzer cargo referencing 0.37.4 cache/UriCache#cache.: HashMaprust-analyzer cargo hashbrown 0.16.1 map/HashMap#::newrust-analyzer cargo hashbrown 0.16.1 map/impl#[`HashMap<K, V>`]new().(), |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | pub(craterust-analyzer cargo referencing 0.37.4 crate/) fn with_capacityrust-analyzer cargo referencing 0.37.4 cache/impl#[UriCache]with_capacity().(capacity: usize) -> Selfrust-analyzer cargo referencing 0.37.4 cache/impl#[UriCache] { |
| 25 | Selfrust-analyzer cargo referencing 0.37.4 cache/impl#[UriCache] { |
| 26 | cacherust-analyzer cargo referencing 0.37.4 cache/UriCache#cache.: HashMaprust-analyzer cargo hashbrown 0.16.1 map/HashMap#::with_capacityrust-analyzer cargo hashbrown 0.16.1 map/impl#[`HashMap<K, V>`]with_capacity().(capacity), |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | pub(craterust-analyzer cargo referencing 0.37.4 crate/) fn resolve_againstrust-analyzer cargo referencing 0.37.4 cache/impl#[UriCache]resolve_against().( |
| 31 | &mut self, |
| 32 | base: &Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<&str>, |
| 33 | uri: impl AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<str>, |
| 34 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>, Errorrust-analyzer cargo referencing 0.37.4 error/Error#> { |
| 35 | let base_str = base.as_strrust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`Uri<T>`]as_str().(); |
| 36 | let reference = uri.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().(); |
| 37 | |
| 38 | let resolved = match self.cacherust-analyzer cargo referencing 0.37.4 cache/UriCache#cache..entry_refrust-analyzer cargo hashbrown 0.16.1 map/impl#[`HashMap<K, V, S, A>`]entry_ref().(base_str) { |
| 39 | EntryRefrust-analyzer cargo hashbrown 0.16.1 map/EntryRef#::Occupiedrust-analyzer cargo hashbrown 0.16.1 map/EntryRef#Occupied#(mut entry) => { |
| 40 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(cached) = entry.getrust-analyzer cargo hashbrown 0.16.1 map/impl#[`OccupiedEntry<'a, K, V, S, A>`]get().().getrust-analyzer cargo hashbrown 0.16.1 map/impl#[`HashMap<K, V, S, A>`]get().(reference) { |
| 41 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().(cached)); |
| 42 | } |
| 43 | |
| 44 | let resolved = Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T>`]new().(urirust-analyzer cargo referencing 0.37.4 uri/::resolve_againstrust-analyzer cargo referencing 0.37.4 uri/resolve_against().(base, reference)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().); |
| 45 | entry |
| 46 | .get_mutrust-analyzer cargo hashbrown 0.16.1 map/impl#[`OccupiedEntry<'a, K, V, S, A>`]get_mut().() |
| 47 | .insertrust-analyzer cargo hashbrown 0.16.1 map/impl#[`HashMap<K, V, S, A>`]insert().(reference.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().(&resolved)); |
| 48 | resolved |
| 49 | } |
| 50 | EntryRefrust-analyzer cargo hashbrown 0.16.1 map/EntryRef#::Vacantrust-analyzer cargo hashbrown 0.16.1 map/EntryRef#Vacant#(entry) => { |
| 51 | let resolved = Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T>`]new().(urirust-analyzer cargo referencing 0.37.4 uri/::resolve_againstrust-analyzer cargo referencing 0.37.4 uri/resolve_against().(base, reference)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().); |
| 52 | let mut inner = HashMaprust-analyzer cargo hashbrown 0.16.1 map/HashMap#::with_capacityrust-analyzer cargo hashbrown 0.16.1 map/impl#[`HashMap<K, V>`]with_capacity().(1); |
| 53 | inner.insertrust-analyzer cargo hashbrown 0.16.1 map/impl#[`HashMap<K, V, S, A>`]insert().(reference.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().(&resolved)); |
| 54 | entry.insertrust-analyzer cargo hashbrown 0.16.1 map/impl#[`VacantEntryRef<'map, 'key, K, Q, V, S, A>`]insert().(inner); |
| 55 | resolved |
| 56 | } |
| 57 | }; |
| 58 | |
| 59 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(resolved) |
| 60 | } |
| 61 | |
| 62 | pub(craterust-analyzer cargo referencing 0.37.4 crate/) fn into_sharedrust-analyzer cargo referencing 0.37.4 cache/impl#[UriCache]into_shared().(self) -> SharedUriCacherust-analyzer cargo referencing 0.37.4 cache/SharedUriCache# { |
| 63 | SharedUriCacherust-analyzer cargo referencing 0.37.4 cache/SharedUriCache# { |
| 64 | cacherust-analyzer cargo referencing 0.37.4 cache/SharedUriCache#cache.: RwLockrust-analyzer cargo parking_lot 0.12.5 rwlock/RwLock#::newrust-analyzer cargo lock_api 0.4.14 rwlock/impl#[`RwLock<R, T>`]new().(self.cacherust-analyzer cargo referencing 0.37.4 cache/UriCache#cache.), |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | /// A dedicated type for URI resolution caching. |
| 70 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 71 | pub(craterust-analyzer cargo referencing 0.37.4 crate/) struct SharedUriCacherust-analyzer cargo referencing 0.37.4 cache/SharedUriCache# { |
| 72 | cacherust-analyzer cargo referencing 0.37.4 cache/SharedUriCache#cache.: RwLockrust-analyzer cargo parking_lot 0.12.5 rwlock/RwLock#<CacheMaprust-analyzer cargo referencing 0.37.4 cache/CacheMap#>, |
| 73 | } |
| 74 | |
| 75 | impl Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# for SharedUriCacherust-analyzer cargo referencing 0.37.4 cache/SharedUriCache# { |
| 76 | fn clonerust-analyzer cargo referencing 0.37.4 cache/impl#[SharedUriCache][Clone]clone().(&self) -> Selfrust-analyzer cargo referencing 0.37.4 cache/impl#[SharedUriCache][Clone] { |
| 77 | Selfrust-analyzer cargo referencing 0.37.4 cache/impl#[SharedUriCache][Clone] { |
| 78 | cacherust-analyzer cargo referencing 0.37.4 cache/SharedUriCache#cache.: RwLockrust-analyzer cargo parking_lot 0.12.5 rwlock/RwLock#::newrust-analyzer cargo lock_api 0.4.14 rwlock/impl#[`RwLock<R, T>`]new().( |
| 79 | self.cacherust-analyzer cargo referencing 0.37.4 cache/SharedUriCache#cache. |
| 80 | .readrust-analyzer cargo lock_api 0.4.14 rwlock/impl#[`RwLock<R, T>`]read().() |
| 81 | .iterrust-analyzer cargo hashbrown 0.16.1 map/impl#[`HashMap<K, V, S, A>`]iter().() |
| 82 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(base, entries)| { |
| 83 | ( |
| 84 | base.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().(), |
| 85 | entries |
| 86 | .iterrust-analyzer cargo hashbrown 0.16.1 map/impl#[`HashMap<K, V, S, A>`]iter().() |
| 87 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(reference, value)| (reference.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().(), Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().(value))) |
| 88 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(), |
| 89 | ) |
| 90 | }) |
| 91 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(), |
| 92 | ), |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | impl SharedUriCacherust-analyzer cargo referencing 0.37.4 cache/SharedUriCache# { |
| 98 | pub(craterust-analyzer cargo referencing 0.37.4 crate/) fn resolve_againstrust-analyzer cargo referencing 0.37.4 cache/impl#[SharedUriCache]resolve_against().( |
| 99 | &self, |
| 100 | base: &Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<&str>, |
| 101 | uri: impl AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<str>, |
| 102 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>, Errorrust-analyzer cargo referencing 0.37.4 error/Error#> { |
| 103 | let base_str = base.as_strrust-analyzer cargo fluent-uri 0.4.1 imp/impl#[`Uri<T>`]as_str().(); |
| 104 | let reference = uri.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().(); |
| 105 | |
| 106 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(cached) = self |
| 107 | .cacherust-analyzer cargo referencing 0.37.4 cache/SharedUriCache#cache. |
| 108 | .readrust-analyzer cargo lock_api 0.4.14 rwlock/impl#[`RwLock<R, T>`]read().() |
| 109 | .getrust-analyzer cargo hashbrown 0.16.1 map/impl#[`HashMap<K, V, S, A>`]get().(base_str) |
| 110 | .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|inner| inner.getrust-analyzer cargo hashbrown 0.16.1 map/impl#[`HashMap<K, V, S, A>`]get().(reference)) |
| 111 | { |
| 112 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().(cached)); |
| 113 | } |
| 114 | |
| 115 | let cache = self.cacherust-analyzer cargo referencing 0.37.4 cache/SharedUriCache#cache..upgradable_readrust-analyzer cargo lock_api 0.4.14 rwlock/impl#[`RwLock<R, T>`]upgradable_read().(); |
| 116 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(inner) = cache.getrust-analyzer cargo hashbrown 0.16.1 map/impl#[`HashMap<K, V, S, A>`]get().(base_str).and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|inner| inner.getrust-analyzer cargo hashbrown 0.16.1 map/impl#[`HashMap<K, V, S, A>`]get().(reference)) { |
| 117 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().(inner)); |
| 118 | } |
| 119 | |
| 120 | let resolved = Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T>`]new().(urirust-analyzer cargo referencing 0.37.4 uri/::resolve_againstrust-analyzer cargo referencing 0.37.4 uri/resolve_against().(base, reference)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().); |
| 121 | |
| 122 | let mut cache = RwLockUpgradableReadGuardrust-analyzer cargo parking_lot 0.12.5 rwlock/RwLockUpgradableReadGuard#::upgraderust-analyzer cargo lock_api 0.4.14 rwlock/impl#[`RwLockUpgradableReadGuard<'a, R, T>`]upgrade().(cache); |
| 123 | let inserted = match cache.entry_refrust-analyzer cargo hashbrown 0.16.1 map/impl#[`HashMap<K, V, S, A>`]entry_ref().(base_str) { |
| 124 | EntryRefrust-analyzer cargo hashbrown 0.16.1 map/EntryRef#::Occupiedrust-analyzer cargo hashbrown 0.16.1 map/EntryRef#Occupied#(mut entry) => { |
| 125 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(existing) = entry.getrust-analyzer cargo hashbrown 0.16.1 map/impl#[`OccupiedEntry<'a, K, V, S, A>`]get().().getrust-analyzer cargo hashbrown 0.16.1 map/impl#[`HashMap<K, V, S, A>`]get().(reference) { |
| 126 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().(existing)); |
| 127 | } |
| 128 | entry |
| 129 | .get_mutrust-analyzer cargo hashbrown 0.16.1 map/impl#[`OccupiedEntry<'a, K, V, S, A>`]get_mut().() |
| 130 | .insertrust-analyzer cargo hashbrown 0.16.1 map/impl#[`HashMap<K, V, S, A>`]insert().(reference.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().(&resolved)); |
| 131 | resolved |
| 132 | } |
| 133 | EntryRefrust-analyzer cargo hashbrown 0.16.1 map/EntryRef#::Vacantrust-analyzer cargo hashbrown 0.16.1 map/EntryRef#Vacant#(entry) => { |
| 134 | let mut inner = HashMaprust-analyzer cargo hashbrown 0.16.1 map/HashMap#::with_capacityrust-analyzer cargo hashbrown 0.16.1 map/impl#[`HashMap<K, V>`]with_capacity().(1); |
| 135 | inner.insertrust-analyzer cargo hashbrown 0.16.1 map/impl#[`HashMap<K, V, S, A>`]insert().(reference.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().(&resolved)); |
| 136 | entry.insertrust-analyzer cargo hashbrown 0.16.1 map/impl#[`VacantEntryRef<'map, 'key, K, Q, V, S, A>`]insert().(inner); |
| 137 | resolved |
| 138 | } |
| 139 | }; |
| 140 | |
| 141 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(inserted) |
| 142 | } |
| 143 | |
| 144 | pub(craterust-analyzer cargo referencing 0.37.4 crate/) fn into_localrust-analyzer cargo referencing 0.37.4 cache/impl#[SharedUriCache]into_local().(self) -> UriCacherust-analyzer cargo referencing 0.37.4 cache/UriCache# { |
| 145 | UriCacherust-analyzer cargo referencing 0.37.4 cache/UriCache# { |
| 146 | cacherust-analyzer cargo referencing 0.37.4 cache/UriCache#cache.: self.cacherust-analyzer cargo referencing 0.37.4 cache/SharedUriCache#cache..into_innerrust-analyzer cargo lock_api 0.4.14 rwlock/impl#[`RwLock<R, T>`]into_inner().(), |
| 147 | } |
| 148 | } |
| 149 | } |