#[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
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
impl IndexValue
Sourcepub fn order_bytes(&self) -> Vec<u8> ⓘ
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());Sourcepub fn window_value(&self, shape: WindowShape) -> Option<i64>
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
impl IndexValue
Sourcepub fn coerce(ty: ValType, raw: &[u8]) -> Option<IndexValue>
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).
Sourcepub fn parse_literal(ty: ValType, raw: &[u8]) -> Option<IndexValue>
pub fn parse_literal(ty: ValType, raw: &[u8]) -> Option<IndexValue>
Parse a query-side literal (same rules as Self::coerce).
Sourcepub fn as_f64(&self) -> f64
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).
Sourcepub fn approx_bytes(&self) -> usize
pub fn approx_bytes(&self) -> usize
Approximate heap bytes (for the memory formula / IDX.LIST).
Sourcepub fn render(&self) -> Vec<u8> ⓘ
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");Sourcepub fn encode(&self, out: &mut Vec<u8>)
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]);Sourcepub fn decode(b: &[u8], pos: &mut usize) -> Option<IndexValue>
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
impl Clone for IndexValue
Source§fn clone(&self) -> IndexValue
fn clone(&self) -> IndexValue
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more