Skip to main content

ValueFilter

Enum ValueFilter 

Source
#[non_exhaustive]
pub enum ValueFilter<'a> { Range { field: &'a [u8], min: &'a [u8], max: &'a [u8], }, Eq { field: &'a [u8], value: &'a [u8], }, }
Expand description

One FILTER predicate: which stored value field it reads, and the test on it — the wire’s RANGE / EQ shapes, in-process.

The bounds are raw bytes and are coerced with the type the field was DECLARED as, so a numeric range compares numerically rather than lexicographically.

use kevy_embedded::ValueFilter;

let cheap = ValueFilter::Range { field: b"price", min: b"0", max: b"10" };
assert_ne!(cheap, ValueFilter::Eq { field: b"price", value: b"5" });

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Range

field between min and max, both inclusive.

// u:1 (age 30, paid, total 5), u:2 (40, paid, 20), u:3 (50, due, 8)
let f = [ValueFilter::Range { field: b"total", min: b"5", max: b"10" }];
assert_eq!(keys(ScalarQueryOpts::default().with_filters(&f))?, [b"u:1".to_vec(), b"u:3".to_vec()]);

Fields

§field: &'a [u8]

The declared value field to read.

// u:1 (age 30, paid, total 5), u:2 (40, paid, 20), u:3 (50, due, 8)
// `total` is declared I64, so the bounds compare as numbers, not bytes
let f = [ValueFilter::Range { field: b"total", min: b"9", max: b"100" }];
assert_eq!(keys(ScalarQueryOpts::default().with_filters(&f))?, [b"u:2".to_vec()]);
§min: &'a [u8]

Lower bound, inclusive.

// u:1 (age 30, paid, total 5), u:2 (40, paid, 20), u:3 (50, due, 8)
let f = [ValueFilter::Range { field: b"total", min: b"8", max: b"99" }];
assert_eq!(keys(ScalarQueryOpts::default().with_filters(&f))?.len(), 2, "8 itself is in");
§max: &'a [u8]

Upper bound, inclusive.

// u:1 (age 30, paid, total 5), u:2 (40, paid, 20), u:3 (50, due, 8)
let f = [ValueFilter::Range { field: b"total", min: b"0", max: b"8" }];
assert_eq!(keys(ScalarQueryOpts::default().with_filters(&f))?.len(), 2, "8 itself is in");
§

Eq

field exactly value.

// u:1 (age 30, paid, total 5), u:2 (40, paid, 20), u:3 (50, due, 8)
let f = [ValueFilter::Eq { field: b"status", value: b"due" }];
assert_eq!(keys(ScalarQueryOpts::default().with_filters(&f))?, [b"u:3".to_vec()]);

Fields

§field: &'a [u8]

The declared value field to read.

// u:1 (age 30, paid, total 5), u:2 (40, paid, 20), u:3 (50, due, 8)
// a field the index does not store is refused, not read as empty
let f = [ValueFilter::Eq { field: b"email", value: b"x" }];
assert!(keys(ScalarQueryOpts::default().with_filters(&f)).is_err());
§value: &'a [u8]

The value to match.

// u:1 (age 30, paid, total 5), u:2 (40, paid, 20), u:3 (50, due, 8)
let f = [ValueFilter::Eq { field: b"total", value: b"20" }];
assert_eq!(keys(ScalarQueryOpts::default().with_filters(&f))?, [b"u:2".to_vec()]);

Trait Implementations§

Source§

impl<'a> Clone for ValueFilter<'a>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for ValueFilter<'a>

Source§

impl<'a> Debug for ValueFilter<'a>

Source§

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

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

impl<'a> Eq for ValueFilter<'a>

Source§

impl<'a> Hash for ValueFilter<'a>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'a> PartialEq for ValueFilter<'a>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<'a> StructuralPartialEq for ValueFilter<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for ValueFilter<'a>

§

impl<'a> RefUnwindSafe for ValueFilter<'a>

§

impl<'a> Send for ValueFilter<'a>

§

impl<'a> Sync for ValueFilter<'a>

§

impl<'a> Unpin for ValueFilter<'a>

§

impl<'a> UnsafeUnpin for ValueFilter<'a>

§

impl<'a> UnwindSafe for ValueFilter<'a>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.