pub struct ListProps {
pub start_after_key: StartAfter,
pub filter: Filter,
pub order: Order,
pub limit: usize,
}Expand description
Configuration structure for listing cache entries with filtering, ordering, and pagination.
ListProps allows you to customize how cache entries are retrieved:
- Filter by key patterns
- Sort in ascending or descending order
- Paginate results with starting points and limits
§Examples
§Basic Usage
use quickleaf::{ListProps, Order};
use quickleaf::Filter;
use quickleaf::Cache;
use quickleaf::valu3::traits::ToValueBehavior;
let mut cache = Cache::new(10);
cache.insert("apple", 1);
cache.insert("banana", 2);
cache.insert("apricot", 3);
let props = ListProps::default()
.order(Order::Desc)
.filter(Filter::StartWith("ap".to_string()));
let results = cache.list(props).unwrap();
assert_eq!(results.len(), 2);§Pagination
use quickleaf::ListProps;
use quickleaf::Cache;
use quickleaf::valu3::traits::ToValueBehavior;
let mut cache = Cache::new(20);
for i in 0..20 {
cache.insert(format!("key_{:02}", i), i);
}
// Get first page (default limit is 10)
let props = ListProps::default();
let page1 = cache.list(props).unwrap();
assert_eq!(page1.len(), 10);
// Get next page starting after the last key from page1
let last_key = &page1.last().unwrap().0;
let props = ListProps::default().start_after_key(last_key);
let page2 = cache.list(props).unwrap();
assert_eq!(page2.len(), 10);Fields§
§start_after_key: StartAfterStarting point for pagination.
filter: FilterFilter to apply to keys.
order: OrderSort order for results.
limit: usizeMaximum number of results to return.
Implementations§
Source§impl ListProps
impl ListProps
Sourcepub fn start_after_key(self, key: &str) -> Self
pub fn start_after_key(self, key: &str) -> Self
Sets the starting point for pagination.
§Examples
use quickleaf::ListProps;
use quickleaf::Cache;
use quickleaf::valu3::traits::ToValueBehavior;
let mut cache = Cache::new(10);
cache.insert("apple", 1);
cache.insert("banana", 2);
cache.insert("cherry", 3);
let props = ListProps::default().start_after_key("banana");
let results = cache.list(props).unwrap();
// Will return entries after "banana"Sourcepub fn filter(self, filter: Filter) -> Self
pub fn filter(self, filter: Filter) -> Self
Sets the filter for key matching.
§Examples
use quickleaf::ListProps;
use quickleaf::Filter;
use quickleaf::Cache;
use quickleaf::valu3::traits::ToValueBehavior;
let mut cache = Cache::new(10);
cache.insert("user_123", 1);
cache.insert("user_456", 2);
cache.insert("admin_789", 3);
let props = ListProps::default()
.filter(Filter::StartWith("user_".to_string()));
let results = cache.list(props).unwrap();
assert_eq!(results.len(), 2);Sourcepub fn order(self, order: Order) -> Self
pub fn order(self, order: Order) -> Self
Sets the sort order for results.
§Examples
use quickleaf::{ListProps, Order};
use quickleaf::Cache;
use quickleaf::valu3::traits::ToValueBehavior;
let mut cache = Cache::new(10);
cache.insert("zebra", 1);
cache.insert("apple", 2);
let props = ListProps::default().order(Order::Desc);
let results = cache.list(props).unwrap();
let keys: Vec<_> = results.iter().map(|(k, _)| k.as_str()).collect();
assert_eq!(keys, vec!["zebra", "apple"]);Sourcepub fn limit(self, limit: usize) -> Self
pub fn limit(self, limit: usize) -> Self
Sets the maximum number of results to return.
§Examples
use quickleaf::ListProps;
use quickleaf::Cache;
use quickleaf::valu3::traits::ToValueBehavior;
let mut cache = Cache::new(20);
for i in 0..15 {
cache.insert(format!("key_{:02}", i), i);
}
// Limit results to 5 items
let props = ListProps::default().limit(5);
let results = cache.list(props).unwrap();
assert_eq!(results.len(), 5);Trait Implementations§
Source§impl From<StartAfter> for ListProps
impl From<StartAfter> for ListProps
Source§fn from(start_after_key: StartAfter) -> Self
fn from(start_after_key: StartAfter) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for ListProps
impl RefUnwindSafe for ListProps
impl Send for ListProps
impl Sync for ListProps
impl Unpin for ListProps
impl UnwindSafe for ListProps
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