| 1 | use hashlinkrust-analyzer cargo hashlink 0.12.1 crate/::lru_cacherust-analyzer cargo hashlink 0.12.1 lru_cache/::LruCacherust-analyzer cargo hashlink 0.12.1 lru_cache/LruCache#; |
| 2 | |
| 3 | /// A cache for prepared statements. When full, the least recently used |
| 4 | /// statement gets removed. |
| 5 | #[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:)] |
| 6 | pub struct StatementCacherust-analyzer cargo sqlx-core 0.8.3 common/statement_cache/StatementCache#<T> { |
| 7 | innerrust-analyzer cargo sqlx-core 0.8.3 common/statement_cache/StatementCache#inner.: LruCacherust-analyzer cargo hashlink 0.12.1 lru_cache/LruCache#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, T>, |
| 8 | } |
| 9 | |
| 10 | impl<T> StatementCacherust-analyzer cargo sqlx-core 0.8.3 common/statement_cache/StatementCache#<T> { |
| 11 | /// Create a new cache with the given capacity. |
| 12 | pub fn newrust-analyzer cargo sqlx-core 0.8.3 common/statement_cache/impl#[`StatementCache<T>`]new().(capacity: usize) -> Selfrust-analyzer cargo sqlx-core 0.8.3 common/statement_cache/impl#[`StatementCache<T>`] { |
| 13 | Selfrust-analyzer cargo sqlx-core 0.8.3 common/statement_cache/impl#[`StatementCache<T>`] { |
| 14 | innerrust-analyzer cargo sqlx-core 0.8.3 common/statement_cache/StatementCache#inner.: LruCacherust-analyzer cargo hashlink 0.12.1 lru_cache/LruCache#::newrust-analyzer cargo hashlink 0.12.1 lru_cache/impl#[`LruCache<K, V>`]new().(capacity), |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | /// Returns a mutable reference to the value corresponding to the given key |
| 19 | /// in the cache, if any. |
| 20 | pub fn get_mutrust-analyzer cargo sqlx-core 0.8.3 common/statement_cache/impl#[`StatementCache<T>`]get_mut().(&mut self, k: &str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&mut T> { |
| 21 | self.innerrust-analyzer cargo sqlx-core 0.8.3 common/statement_cache/StatementCache#inner..get_mutrust-analyzer cargo hashlink 0.12.1 lru_cache/impl#[`LruCache<K, V, S>`]get_mut().(k) |
| 22 | } |
| 23 | |
| 24 | /// Inserts a new statement to the cache, returning the least recently used |
| 25 | /// statement id if the cache is full, or if inserting with an existing key, |
| 26 | /// the replaced existing statement. |
| 27 | pub fn insertrust-analyzer cargo sqlx-core 0.8.3 common/statement_cache/impl#[`StatementCache<T>`]insert().(&mut self, k: &str, v: T) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<T> { |
| 28 | let mut lru_item = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 29 | |
| 30 | if self.capacityrust-analyzer cargo sqlx-core 0.8.3 common/statement_cache/impl#[`StatementCache<T>`]capacity().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().self.lenrust-analyzer cargo sqlx-core 0.8.3 common/statement_cache/impl#[`StatementCache<T>`]len().() && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.contains_keyrust-analyzer cargo sqlx-core 0.8.3 common/statement_cache/impl#[`StatementCache<T>`]contains_key().(k) { |
| 31 | lru_item = self.remove_lrurust-analyzer cargo sqlx-core 0.8.3 common/statement_cache/impl#[`StatementCache<T>`]remove_lru().(); |
| 32 | } else if self.contains_keyrust-analyzer cargo sqlx-core 0.8.3 common/statement_cache/impl#[`StatementCache<T>`]contains_key().(k) { |
| 33 | lru_item = self.innerrust-analyzer cargo sqlx-core 0.8.3 common/statement_cache/StatementCache#inner..removerust-analyzer cargo hashlink 0.12.1 lru_cache/impl#[`LruCache<K, V, S>`]remove().(k); |
| 34 | } |
| 35 | |
| 36 | self.innerrust-analyzer cargo sqlx-core 0.8.3 common/statement_cache/StatementCache#inner..insertrust-analyzer cargo hashlink 0.12.1 lru_cache/impl#[`LruCache<K, V, S>`]insert().(k.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), v); |
| 37 | |
| 38 | lru_item |
| 39 | } |
| 40 | |
| 41 | /// The number of statements in the cache. |
| 42 | pub fn lenrust-analyzer cargo sqlx-core 0.8.3 common/statement_cache/impl#[`StatementCache<T>`]len().(&self) -> usize { |
| 43 | self.innerrust-analyzer cargo sqlx-core 0.8.3 common/statement_cache/StatementCache#inner..lenrust-analyzer cargo hashlink 0.12.1 lru_cache/impl#[`LruCache<K, V, S>`]len().() |
| 44 | } |
| 45 | |
| 46 | pub fn is_emptyrust-analyzer cargo sqlx-core 0.8.3 common/statement_cache/impl#[`StatementCache<T>`]is_empty().(&self) -> bool { |
| 47 | self.innerrust-analyzer cargo sqlx-core 0.8.3 common/statement_cache/StatementCache#inner..is_emptyrust-analyzer cargo hashlink 0.12.1 lru_cache/impl#[`LruCache<K, V, S>`]is_empty().() |
| 48 | } |
| 49 | |
| 50 | /// Removes the least recently used item from the cache. |
| 51 | pub fn remove_lrurust-analyzer cargo sqlx-core 0.8.3 common/statement_cache/impl#[`StatementCache<T>`]remove_lru().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<T> { |
| 52 | self.innerrust-analyzer cargo sqlx-core 0.8.3 common/statement_cache/StatementCache#inner..remove_lrurust-analyzer cargo hashlink 0.12.1 lru_cache/impl#[`LruCache<K, V, S>`]remove_lru().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|(_, v)| v) |
| 53 | } |
| 54 | |
| 55 | /// Clear all cached statements from the cache. |
| 56 | pub fn clearrust-analyzer cargo sqlx-core 0.8.3 common/statement_cache/impl#[`StatementCache<T>`]clear().(&mut self) { |
| 57 | self.innerrust-analyzer cargo sqlx-core 0.8.3 common/statement_cache/StatementCache#inner..clearrust-analyzer cargo hashlink 0.12.1 lru_cache/impl#[`LruCache<K, V, S>`]clear().(); |
| 58 | } |
| 59 | |
| 60 | /// True if cache has a value for the given key. |
| 61 | pub fn contains_keyrust-analyzer cargo sqlx-core 0.8.3 common/statement_cache/impl#[`StatementCache<T>`]contains_key().(&mut self, k: &str) -> bool { |
| 62 | self.innerrust-analyzer cargo sqlx-core 0.8.3 common/statement_cache/StatementCache#inner..contains_keyrust-analyzer cargo hashlink 0.12.1 lru_cache/impl#[`LruCache<K, V, S>`]contains_key().(k) |
| 63 | } |
| 64 | |
| 65 | /// Returns the maximum number of statements the cache can hold. |
| 66 | pub fn capacityrust-analyzer cargo sqlx-core 0.8.3 common/statement_cache/impl#[`StatementCache<T>`]capacity().(&self) -> usize { |
| 67 | self.innerrust-analyzer cargo sqlx-core 0.8.3 common/statement_cache/StatementCache#inner..capacityrust-analyzer cargo hashlink 0.12.1 lru_cache/impl#[`LruCache<K, V, S>`]capacity().() |
| 68 | } |
| 69 | |
| 70 | /// Returns true if the cache capacity is more than 0. |
| 71 | #[allow(dead_code)] // Only used for some `cfg`s |
| 72 | pub fn is_enabledrust-analyzer cargo sqlx-core 0.8.3 common/statement_cache/impl#[`StatementCache<T>`]is_enabled().(&self) -> bool { |
| 73 | self.capacityrust-analyzer cargo sqlx-core 0.8.3 common/statement_cache/impl#[`StatementCache<T>`]capacity().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 |
| 74 | } |
| 75 | } |