ListProps

Struct ListProps 

Source
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: StartAfter

Starting point for pagination.

§filter: Filter

Filter to apply to keys.

§order: Order

Sort order for results.

§limit: usize

Maximum number of results to return.

Implementations§

Source§

impl ListProps

Source

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"
Source

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);
Source

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"]);
Source

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 Debug for ListProps

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ListProps

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<Filter> for ListProps

Source§

fn from(filter: Filter) -> Self

Converts to this type from the input type.
Source§

impl From<Order> for ListProps

Source§

fn from(order: Order) -> Self

Converts to this type from the input type.
Source§

impl From<StartAfter> for ListProps

Source§

fn from(start_after_key: StartAfter) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.