Value

Enum Value 

Source
pub enum Value {
    Null(DataType),
    Integer(i64),
    Float(f64),
    Text(SmartString),
    Boolean(bool),
    Timestamp(DateTime<Utc>),
    Json(CompactArc<str>),
}
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)
  • Json(Arc): 8 bytes thin pointer with null niche
  • Rust stores Value’s discriminant in these niche values

Note: Text uses SmartString for inline storage of strings up to 15 bytes. Longer strings use Arc 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)

§

Json(CompactArc<str>)

JSON document (CompactArc for cheap cloning, 16-byte fat pointer)

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. This allows string sharing between Arena, Index, and VersionStore.

Source

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

Create a text value from Arc (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 json(value: impl Into<String>) -> Self

Create a JSON value

Source

pub fn json_arc(value: CompactArc<str>) -> Self

Create a JSON value from CompactArc (zero-copy)

Source

pub fn data_type(&self) -> DataType

Returns the data type of this value

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_arc_str(&self) -> Option<CompactArc<str>>

Extract as CompactArc (creates CompactArc for Text, cheap clone for Json)

Source

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

Extract as DateTime

Source

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

Extract as JSON string

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) -> 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 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 · 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 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<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<i8> for Value

Source§

fn from(v: i8) -> 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 From<u8> for Value

Source§

fn from(v: u8) -> 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 FromValue for Value

Source§

fn from_value(value: &Value) -> Result<Self>

Convert a Value to Self
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 · Source§

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

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

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

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

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

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

impl PartialEq for Value

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
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 · 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 · 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 · 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 · 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 ToParam for Value

Source§

fn to_param(&self) -> Value

Convert self into a Value for SQL parameter binding
Source§

impl Eq for Value

Auto Trait Implementations§

§

impl Freeze for Value

§

impl RefUnwindSafe for Value

§

impl Send for Value

§

impl Sync for Value

§

impl Unpin 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<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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 = 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.
Source§

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

Source§

fn vzip(self) -> V