pub struct FnMatcher<T, F>{ /* private fields */ }Expand description
Function-based matcher for maximum flexibility in matching logic.
This matcher allows you to provide a custom function that determines whether a key matches. This is the most flexible matcher and can implement any matching logic you need.
§Examples
use simple_cacher::*;
use std::time::Duration;
let mut cache = SimpleCacher::new(Duration::from_secs(300));
cache.insert(2, "Even number".to_string());
cache.insert(3, "Odd number".to_string());
cache.insert(4, "Even number".to_string());
cache.insert(5, "Odd number".to_string());
// Find even numbers
let even_matcher = FnMatcher::new(|&key: &i32| key % 2 == 0);
let even_numbers = cache.get_all_by_matcher(&even_matcher);
assert_eq!(even_numbers.len(), 2); // 2 and 4Implementations§
Trait Implementations§
Auto Trait Implementations§
impl<T, F> Freeze for FnMatcher<T, F>where
F: Freeze,
impl<T, F> RefUnwindSafe for FnMatcher<T, F>where
F: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, F> Send for FnMatcher<T, F>
impl<T, F> Sync for FnMatcher<T, F>
impl<T, F> Unpin for FnMatcher<T, F>
impl<T, F> UnwindSafe for FnMatcher<T, F>where
F: UnwindSafe,
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more