scufflecloud_redis_module/
utils.rs

1use std::collections::BTreeSet;
2use std::num::NonZeroU64;
3use std::rc::Rc;
4
5use redis_module_ext::utils::redis_time_millis;
6
7pub type Str = Rc<str>;
8
9pub fn now() -> NonZeroU64 {
10    NonZeroU64::new(redis_time_millis() as u64).unwrap()
11}
12
13pub trait SetExt<T> {
14    fn pop_first_if(&mut self, f: impl FnMut(&T) -> bool) -> Option<T>;
15}
16
17impl<T: Ord> SetExt<T> for BTreeSet<T> {
18    fn pop_first_if(&mut self, mut f: impl FnMut(&T) -> bool) -> Option<T> {
19        if f(self.first()?) { self.pop_first() } else { None }
20    }
21}