From e66bc25f3a27d46b06edc4d4f5f42e4913d50ee4 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 23 Mar 2026 19:01:32 +0000 Subject: [PATCH] chore(rust): replace unwrap() with safe fallback in TtlLruCache Replaced `unwrap()` calls when initializing `NonZeroUsize` for the `LruCache` capacity. Used `unwrap_or(NonZeroUsize::MIN)` to provide a safe fallback of 1 instead of panicking, improving the robustness and maintainability of the search cache. - Modified `TtlLruCache::new()` - Modified `TtlLruCache::with_config()` Verified with a standalone Rust script since `cargo test` was unavailable due to network constraints. Co-authored-by: LeandroPG19 <151863062+LeandroPG19@users.noreply.github.com> --- rust/src/search/cache.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rust/src/search/cache.rs b/rust/src/search/cache.rs index 833a53c..c9e378f 100644 --- a/rust/src/search/cache.rs +++ b/rust/src/search/cache.rs @@ -24,7 +24,7 @@ impl TtlLruCache { /// Create new cache with configured max size and TTL. pub fn new() -> Self { Self { - inner: LruCache::new(NonZeroUsize::new(CACHE_MAX_ENTRIES).unwrap()), + inner: LruCache::new(NonZeroUsize::new(CACHE_MAX_ENTRIES).unwrap_or(NonZeroUsize::MIN)), ttl: Duration::from_secs(CACHE_TTL_SECS), } } @@ -32,7 +32,7 @@ impl TtlLruCache { /// Create cache with custom capacity and TTL. pub fn with_config(max_entries: usize, ttl_secs: u64) -> Self { Self { - inner: LruCache::new(NonZeroUsize::new(max_entries.max(1)).unwrap()), + inner: LruCache::new(NonZeroUsize::new(max_entries).unwrap_or(NonZeroUsize::MIN)), ttl: Duration::from_secs(ttl_secs), } }