Skip to main content

Value

Enum Value 

Source
pub enum Value {
    Null(DataType),
    Integer(i64),
    Float(f64),
    Text(SmartString),
    Boolean(bool),
    Timestamp(DateTime<Utc>),
    Extension(CompactArc<[u8]>),
}
Expand description

A runtime value with type information

Each variant carries its data directly, avoiding the need for interface indirection or separate value references.

§Memory Layout (16 bytes)

Value is exactly 16 bytes due to niche optimization:

  • Text(SmartString): 16 bytes with niches in tag byte (values 17-255 unused)
  • Extension(CompactArc<u8>): 8 bytes (thin pointer), leaving niche bytes free
  • Rust stores Value’s discriminant in SmartString’s niche values

§Extension Variant

The Extension variant is a catch-all for all complex types (JSON, Vector, Blob, etc.) It stores a single CompactArc<[u8]> (8 bytes) where byte[0] is the DataType tag and byte[1..] is the payload. This keeps Value at exactly 7 variants forever — new types are added by extending DataType (a 1-byte #[repr(u8)] enum).

Note: Text uses SmartString for inline storage of strings up to 15 bytes. Longer strings use Arc<str> for O(1) clone and sharing.

Variants§

§

Null(DataType)

NULL value with optional type hint

§

Integer(i64)

64-bit signed integer

§

Float(f64)

64-bit floating point

§

Text(SmartString)

UTF-8 text string (SmartString: inline ≤15 bytes, Arc for larger)

§

Boolean(bool)

Boolean value

§

Timestamp(DateTime<Utc>)

Timestamp (UTC)

§

Extension(CompactArc<[u8]>)

Extension type: byte[0] = DataType tag, byte[1..] = payload

  • Json: byte[0]=6, byte[1..]=UTF-8 bytes (access via as_json())
  • Vector: byte[0]=7, byte[1..]=packed LE f32 bytes (access via as_vector_f32())
  • Future types (Blob, Array, etc.) add DataType variants, not Value variants

Implementations§

Source§

impl Value

Source

pub fn null(data_type: DataType) -> Self

Create a NULL value with a type hint

Source

pub fn null_unknown() -> Self

Create a NULL value with unknown type

Source

pub fn integer(value: i64) -> Self

Create an integer value

Source

pub fn float(value: f64) -> Self

Create a float value

Source

pub fn text(value: impl Into<String>) -> Self

Create a text value

Uses SmartString::from_string_shared() for heap strings to enable O(1) clone via Arc<str>. This allows string sharing between Arena, Index, and VersionStore.

Source

pub fn text_arc(value: Arc<str>) -> Self

Create a text value from Arc<str> (zero-copy for heap strings)

Preserves the Arc reference for O(1) clone and sharing.

Source

pub fn boolean(value: bool) -> Self

Create a boolean value

Source

pub fn timestamp(value: DateTime<Utc>) -> Self

Create a timestamp value

Source

pub fn try_json(value: impl Into<String>) -> Result<Self>

Create a validated JSON value.

Source

pub fn vector(data: Vec<f32>) -> Self

Create a vector value from f32 data (stored as packed LE f32 bytes in Extension)

Source

pub fn try_vector_from_bytes(raw_f32_bytes: CompactArc<[u8]>) -> Result<Self>

Create a vector value from pre-packed little-endian f32 bytes.

Source

pub fn uuid(bytes: [u8; 16]) -> Self

Create a UUID value from raw 16-byte UUID storage.

Source

pub fn uuid_v7() -> Self

Create a new UUIDv7 value.

UUIDv7 is time-ordered, which makes it much friendlier for primary-key B-tree indexes than fully random UUIDv4 values.

Source

pub fn try_decimal(unscaled: i128, precision: u8, scale: u8) -> Result<Self>

Create an exact decimal value.

Payload layout:

  • byte 0: DataType::Decimal tag;
  • bytes 1..17: little-endian i128 unscaled integer;
  • byte 17: precision;
  • byte 18: scale.
Source

pub fn date(days_since_unix_epoch: i32) -> Self

Create a calendar date value from days since Unix epoch.

Source

pub fn bytes(bytes: Vec<u8>) -> Self

Create a raw byte-string value.

Source

pub fn try_external( type_ref: ExternalTypeRef, payload: impl AsRef<[u8]>, ) -> Result<Self>

Create a typed external value from canonical plugin codec bytes.

Semantic codec validation is performed by the admitted plugin host at SQL/wire ingress. This constructor enforces the context-free envelope bounds shared by WAL and immutable artifact readers.

Source

pub fn data_type(&self) -> DataType

Returns the data type of this value

Source

pub fn logical_type(&self) -> LogicalTypeRef

Return the complete built-in or external logical type identity.

Source

pub fn is_external(&self) -> bool

Return whether this value carries the reserved external-type envelope.

This intentionally checks only the marker. Full envelope validation is owned by Value::as_external and the row/WAL/file admission paths.

Source

pub fn as_external(&self) -> Option<ExternalValueRef<'_>>

Borrow the external envelope without exposing its compact storage.

Source

pub fn validate_shape(&self) -> Result<()>

Validate the physical shape of a value before it crosses a row, WAL or file-format admission boundary.

Source

pub fn is_null(&self) -> bool

Returns true if this value is NULL

Source

pub fn as_int64(&self) -> Option<i64>

Extract as i64, with type coercion

Returns None if:

  • Value is NULL
  • Conversion is not possible
Source

pub fn as_float64(&self) -> Option<f64>

Extract as f64, with type coercion

Source

pub fn as_boolean(&self) -> Option<bool>

Extract as boolean, with type coercion

Source

pub fn as_string(&self) -> Option<String>

Extract as String, with type coercion

Source

pub fn as_str(&self) -> Option<&str>

Extract as string reference (avoids clone for Text/Json)

Source

pub fn as_timestamp(&self) -> Option<DateTime<Utc>>

Extract as DateTime<Utc>

Source

pub fn as_json(&self) -> Option<&str>

Extract as JSON string

Source

pub fn as_vector_f32(&self) -> Option<Vec<f32>>

Extract vector as Vec<f32> (reads packed LE f32 bytes from Extension payload)

Source

pub fn as_uuid_bytes(&self) -> Option<[u8; 16]>

Extract UUID as raw 16 bytes.

Source

pub fn as_decimal_parts(&self) -> Option<(i128, u8, u8)>

Extract exact decimal parts: (unscaled, precision, scale).

Source

pub fn as_date_days(&self) -> Option<i32>

Extract calendar date as days since Unix epoch.

Source

pub fn as_bytes_value(&self) -> Option<&[u8]>

Extract raw bytes from a BYTES/BLOB/BINARY value.

Source

pub fn compare(&self, other: &Value) -> Result<Ordering>

Compare two values for ordering

Returns:

  • Ok(Ordering::Less) if self < other
  • Ok(Ordering::Equal) if self == other
  • Ok(Ordering::Greater) if self > other
  • Err if comparison is not possible
Source

pub fn from_typed(value: Option<&dyn Any>, data_type: DataType) -> Result<Self>

Create a Value from a typed value with explicit data type

Source

pub fn coerce_to_type(&self, target_type: DataType) -> Value

Coerce this value to the target data type

Type coercion rules:

  • Integer column receiving Float → converts to Integer
  • Float column receiving Integer → converts to Float
  • Text column receiving any type → converts to Text
  • Timestamp column receiving String → parses timestamp
  • JSON column receiving valid JSON string → stores as JSON
  • Boolean column receiving Integer/String → converts to Boolean

Returns the coerced value, or NULL if coercion fails.

Source

pub fn try_coerce_to_type(&self, target_type: DataType) -> Result<Value>

Checked coercion to the target data type.

This is the strict counterpart to Value::coerce_to_type. It preserves the normal SQL rule that NULL casts to typed NULL, but treats non-NULL-to-NULL conversion as a runtime type error. Use this for explicit SQL CAST and other user-visible expression evaluation boundaries where silently producing NULL would hide bad data.

Source

pub fn into_coerce_to_type(self, target_type: DataType) -> Value

Coerce value to target type, consuming self OPTIMIZATION: Avoids clone when types already match

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Value

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 Value

Source§

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

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

impl Default for Value

Source§

fn default() -> Self

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

impl Display for Value

Source§

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

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

impl Eq for Value

Source§

impl From<&str> for Value

Source§

fn from(v: &str) -> Self

Converts to this type from the input type.
Source§

impl From<Arc<str>> for Value

Source§

fn from(v: Arc<str>) -> Self

Converts to this type from the input type.
Source§

impl From<DateTime<Utc>> for Value

Source§

fn from(v: DateTime<Utc>) -> Self

Converts to this type from the input type.
Source§

impl<T: Into<Value>> From<Option<T>> for Value

Source§

fn from(v: Option<T>) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Value

Source§

fn from(v: String) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for Value

Source§

fn from(v: bool) -> Self

Converts to this type from the input type.
Source§

impl From<f32> for Value

Source§

fn from(v: f32) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for Value

Source§

fn from(v: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i8> for Value

Source§

fn from(v: i8) -> Self

Converts to this type from the input type.
Source§

impl From<i16> for Value

Source§

fn from(v: i16) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for Value

Source§

fn from(v: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for Value

Source§

fn from(v: i64) -> Self

Converts to this type from the input type.
Source§

impl From<u8> for Value

Source§

fn from(v: u8) -> Self

Converts to this type from the input type.
Source§

impl From<u16> for Value

Source§

fn from(v: u16) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for Value

Source§

fn from(v: u32) -> Self

Converts to this type from the input type.
Source§

impl FromIterator<Value> for Row

Source§

fn from_iter<I: IntoIterator<Item = Value>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl Hash for Value

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 Ord for Value

Total ordering implementation for Value

This is required for using Value as a key in BTreeMap/BTreeSet. The ordering is defined as follows:

  1. NULLs are always ordered first (smallest)
  2. Numeric types (Integer, Float) are compared by numeric value (consistent with PartialEq)
  3. Other different data types are ordered by their type discriminant
  4. Same data types use their natural ordering

IMPORTANT: This ordering MUST be consistent with PartialEq. Since Integer(5) == Float(5.0) per PartialEq, we must ensure Integer(5).cmp(&Float(5.0)) == Ordering::Equal. Violating this contract causes BTreeMap corruption.

Note: This differs from SQL NULL semantics where NULL comparisons return UNKNOWN. This ordering is only for internal index structure.

Source§

fn cmp(&self, other: &Self) -> 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 Value

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 PartialOrd for Value

Source§

fn partial_cmp(&self, other: &Self) -> 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

Auto Trait Implementations§

§

impl Freeze for Value

§

impl RefUnwindSafe for Value

§

impl Send for Value

§

impl Sync for Value

§

impl Unpin for Value

§

impl UnsafeUnpin for Value

§

impl UnwindSafe for Value

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> CompactArcDrop for T

Source§

unsafe fn drop_and_dealloc(ptr: *mut u8)

Drop the contained data and deallocate the header+data allocation. 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> Same for T

Source§

type Output = T

Should always be Self
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V