Skip to main content

IndexValue

Enum IndexValue 

Source
#[non_exhaustive]
pub enum IndexValue { I64(i64), F64(f64), Str(Vec<u8>), }
Expand description

One indexed scalar. Ordering is total within a type; the catalog guarantees a segment only ever holds one variant.

Values enter through coerce, which applies the declared type to a field’s raw bytes; a row whose field does not coerce is left out of the index.

use kevy_index::{IndexValue, ValType};

let age = IndexValue::coerce(ValType::I64, b" 41 ");
assert_eq!(age, Some(IndexValue::I64(41)));
assert_eq!(IndexValue::coerce(ValType::I64, b"forty"), None);
assert_eq!(IndexValue::coerce(ValType::F64, b"NaN"), None);
assert_eq!(IndexValue::parse_literal(ValType::F64, b"2.5"), Some(IndexValue::F64(2.5)));

assert_eq!(IndexValue::I64(3).as_f64(), 3.0);
assert_eq!(IndexValue::Str(b"kyoto".to_vec()).approx_bytes(), 5);
assert!(IndexValue::F64(-1.0) < IndexValue::F64(0.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.
§

I64(i64)

TYPE i64.

use kevy_index::{IndexValue, ValType};
assert_eq!(IndexValue::coerce(ValType::I64, b"-7"), Some(IndexValue::I64(-7)));
§

F64(f64)

TYPE f64 (never NaN — coercion rejects it).

use kevy_index::{IndexValue, ValType};
assert_eq!(IndexValue::coerce(ValType::F64, b"1e3"), Some(IndexValue::F64(1000.0)));
§

Str(Vec<u8>)

TYPE str (raw bytes, memcmp order).

use kevy_index::{IndexValue, ValType};
let v = IndexValue::coerce(ValType::Str, b"Zed").unwrap();
assert_eq!(v, IndexValue::Str(b"Zed".to_vec()));
assert!(v < IndexValue::Str(b"apple".to_vec()), "bytes compare, not letters");

Implementations§

Source§

impl IndexValue

Source

pub fn order_bytes(&self) -> Vec<u8> ⓘ

The order-preserving bytes of one value — crate::order_key’s transform, taken from an already-coerced IndexValue. The pin test holds the two in lockstep.

use kevy_index::IndexValue;
assert!(IndexValue::I64(-1).order_bytes() < IndexValue::I64(1).order_bytes());
Source

pub fn window_value(&self, shape: WindowShape) -> Option<i64>

The window-column value a tree entry carries, under shape. None = the entry cannot carry one (wrong variant / short bytes) — the caller treats the tree as having no boundary to advance.

use kevy_index::{IndexValue, WindowShape};
assert_eq!(IndexValue::I64(42).window_value(WindowShape::PlainI64), Some(42));
assert_eq!(IndexValue::I64(42).window_value(WindowShape::CompositeLed), None);
Source§

impl IndexValue

Source

pub fn coerce(ty: ValType, raw: &[u8]) -> Option<IndexValue>

Coerce raw field bytes per the declared type. None = the row is excluded from the index (and counted as a coerce failure).

Source

pub fn parse_literal(ty: ValType, raw: &[u8]) -> Option<IndexValue>

Parse a query-side literal (same rules as Self::coerce).

Source

pub fn as_f64(&self) -> f64

Numeric view for aggregation (Str = 0.0; agg kinds only admit numeric types at CREATE, so this arm is unreachable there).

Source

pub fn approx_bytes(&self) -> usize

Approximate heap bytes (for the memory formula / IDX.LIST).

Source

pub fn render(&self) -> Vec<u8> ⓘ

The text a reply shows for this value: decimal for i64, Rust’s shortest round-trip form for f64, the raw bytes for str.

use kevy_index::IndexValue;
assert_eq!(IndexValue::I64(-7).render(), b"-7");
assert_eq!(IndexValue::F64(2.5).render(), b"2.5");
assert_eq!(IndexValue::Str(b"kyoto".to_vec()).render(), b"kyoto");
Source

pub fn encode(&self, out: &mut Vec<u8>)

Append the tagged binary form cursors and shard replies carry: a tag byte (0 i64, 1 f64, 2 str), then the value — eight little-endian bytes, or a u32 little-endian length and the bytes.

use kevy_index::IndexValue;
let mut out = Vec::new();
IndexValue::I64(1).encode(&mut out);
assert_eq!(out, [0, 1, 0, 0, 0, 0, 0, 0, 0]);
Source

pub fn decode(b: &[u8], pos: &mut usize) -> Option<IndexValue>

Read one encoded value at *pos, advancing pos past it; None on an unknown tag or truncated bytes.

use kevy_index::IndexValue;
let mut buf = Vec::new();
IndexValue::Str(b"ab".to_vec()).encode(&mut buf);
IndexValue::F64(0.5).encode(&mut buf);
let mut pos = 0;
assert_eq!(IndexValue::decode(&buf, &mut pos), Some(IndexValue::Str(b"ab".to_vec())));
assert_eq!(IndexValue::decode(&buf, &mut pos), Some(IndexValue::F64(0.5)));
assert_eq!((pos, IndexValue::decode(&buf, &mut pos)), (buf.len(), None));

Trait Implementations§

Source§

impl Clone for IndexValue

Source§

fn clone(&self) -> IndexValue

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

Source§

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

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

impl Eq for IndexValue

Source§

impl Ord for IndexValue

Source§

fn cmp(&self, other: &IndexValue) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for IndexValue

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialOrd for IndexValue

Source§

fn partial_cmp(&self, other: &IndexValue) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for IndexValue

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> 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.