pub enum Value {
Show 32 variants
Bool(bool),
Int8 {
value: i8,
width: u8,
},
Int16(i16),
Int32(i32),
Int64(i64),
Float32(f32),
Float64(f64),
Decimal {
value: String,
precision: u8,
scale: u8,
},
Char {
value: String,
length: u16,
},
VarChar {
value: String,
length: u16,
},
Text(String),
Blob(Vec<u8>),
Bytes(Vec<u8>),
Date(DateTime<Utc>),
Time(DateTime<Utc>),
LocalDateTime(DateTime<Utc>),
LocalDateTimeNano(DateTime<Utc>),
ZonedDateTime(DateTime<Utc>),
TimeTz(String),
Uuid(Uuid),
Ulid(Ulid),
Json(Box<Value>),
Jsonb(Box<Value>),
Array {
elements: Vec<Value>,
element_type: Box<Type>,
},
Set {
elements: Vec<String>,
allowed_values: Vec<String>,
},
Enum {
value: String,
allowed_values: Vec<String>,
},
Geometry {
data: GeometryData,
geometry_type: GeometryType,
},
Duration(Duration),
Thing {
table: String,
id: Box<Value>,
},
Object(HashMap<String, Value>),
Null,
ZeroTemporal {
intended_type: Type,
source: Option<String>,
},
}Expand description
Universal value representation with 1:1 correspondence to Type.
Each variant of Value corresponds exactly to one variant of Type,
enabling deterministic conversion via to_typed_value() without inference or fallback.
§Design Principles
- Exact correspondence: Every
Typevariant has exactly one matchingValuevariant - No inference:
to_typed_value()is deterministic - no guessing or fallback - Type metadata included: Variants like
Char,VarChar,Decimalinclude their type parameters - Self-describing: Each value knows its exact type without external context
Variants§
Bool(bool)
Boolean value → Type::Bool
Int8
Tiny integer with display width → Type::Int8 { width }
Int16(i16)
16-bit signed integer → Type::Int16
Int32(i32)
32-bit signed integer → Type::Int32
Int64(i64)
64-bit signed integer → Type::Int64
Float32(f32)
32-bit IEEE 754 floating point → Type::Float32
Float64(f64)
64-bit IEEE 754 floating point → Type::Float64
Decimal
Decimal value with precision/scale → Type::Decimal { precision, scale }
Fields
Char
Fixed-length character string → Type::Char { length }
VarChar
Variable-length character string → Type::VarChar { length }
Text(String)
Unlimited text → Type::Text
Blob(Vec<u8>)
Binary large object → Type::Blob
Bytes(Vec<u8>)
Binary data → Type::Bytes
Date(DateTime<Utc>)
Date only (YYYY-MM-DD) → Type::Date
Time(DateTime<Utc>)
Time only (HH:MM:SS) → Type::Time
LocalDateTime(DateTime<Utc>)
Timestamp without timezone (microsecond precision) → Type::LocalDateTime
LocalDateTimeNano(DateTime<Utc>)
Timestamp with nanosecond precision → Type::LocalDateTimeNano
ZonedDateTime(DateTime<Utc>)
Timestamp with timezone → Type::ZonedDateTime
TimeTz(String)
Time with timezone (stored as string to preserve original format)
→ Type::TimeTz
Note: We intentionally use String instead of DateTime because time and datetime are fundamentally different types. DateTime implies a specific point in time, while time with timezone represents a daily recurring time in a specific timezone. Using DateTime to represent time would misrepresent the semantics.
Uuid(Uuid)
UUID (128-bit) → Type::Uuid
Ulid(Ulid)
ULID (128-bit sortable identifier) → Type::Ulid
Json(Box<Value>)
JSON document → Type::Json
Jsonb(Box<Value>)
Binary JSON (PostgreSQL JSONB) → Type::Jsonb
Array
Array of a specific type → Type::Array { element_type }
Set
MySQL SET type → Type::Set { values }
Fields
Enum
Enumeration type → Type::Enum { values }
Geometry
Spatial/geometry type → Type::Geometry { geometry_type }
Fields
data: GeometryDataGeometry data (WKB bytes or GeoJSON object)
geometry_type: GeometryTypeSpecific geometry variant
Duration(Duration)
Duration type → Type::Duration
Thing
Record reference/link (e.g., SurrealDB Thing) → Type::Thing
Fields
Object(HashMap<String, Value>)
Nested object/document (e.g., MongoDB embedded documents, SurrealDB objects)
→ Type::Object
This differs from Json/Jsonb which are serialized JSON storage types. Object represents a structured nested document with typed fields.
Null
Null value (can be any nullable type)
ZeroTemporal
Source emitted a temporal that is not a valid calendar/chrono value
(e.g. MySQL/MariaDB zero date 0000-00-00).
Distinct from Value::Null: SQL NULL stays Null; MySQL-style
zero dates/timestamps use this sentinel so transforms retain the intended
column type before the SurrealDB sink maps it.
Implementations§
Source§impl Value
impl Value
Sourcepub fn decimal(value: impl Into<String>, precision: u8, scale: u8) -> Self
pub fn decimal(value: impl Into<String>, precision: u8, scale: u8) -> Self
Create a Decimal value.
Sourcepub fn enum_value(value: impl Into<String>, allowed_values: Vec<String>) -> Self
pub fn enum_value(value: impl Into<String>, allowed_values: Vec<String>) -> Self
Create an Enum value.
Sourcepub fn geometry_geojson(data: Value, geometry_type: GeometryType) -> Self
pub fn geometry_geojson(data: Value, geometry_type: GeometryType) -> Self
Create a Geometry value from GeoJSON.
Sourcepub fn zero_temporal(intended_type: Type, source: Option<String>) -> Self
pub fn zero_temporal(intended_type: Type, source: Option<String>) -> Self
Create a zero-temporal sentinel with the intended column type.
Sourcepub fn canonical_zero_literal(intended_type: &Type) -> &'static str
pub fn canonical_zero_literal(intended_type: &Type) -> &'static str
Canonical MySQL-style zero literal for an intended temporal type.
Sourcepub fn is_mysql_zero_temporal_literal(s: &str) -> bool
pub fn is_mysql_zero_temporal_literal(s: &str) -> bool
Whether s is a MySQL/MariaDB zero date or zero datetime literal.
Matches 0000-00-00 and 0000-00-00 00:00:00 with optional fractional seconds.
Sourcepub fn is_mysql_zero_date_ymd(year: u16, month: u8, day: u8) -> bool
pub fn is_mysql_zero_date_ymd(year: u16, month: u8, day: u8) -> bool
Whether year/month/day are the MySQL zero-date triple (0, 0, 0).
Sourcepub fn is_zero_temporal_type(intended_type: &Type) -> bool
pub fn is_zero_temporal_type(intended_type: &Type) -> bool
Whether intended_type may be used with Value::ZeroTemporal.
Sourcepub fn is_zero_temporal(&self) -> bool
pub fn is_zero_temporal(&self) -> bool
Check if this value is a zero-temporal sentinel.
Sourcepub fn as_datetime(&self) -> Option<&DateTime<Utc>>
pub fn as_datetime(&self) -> Option<&DateTime<Utc>>
Try to get this value as a DateTime.
Sourcepub fn variant_name(&self) -> &'static str
pub fn variant_name(&self) -> &'static str
Get a human-readable description of this value’s variant.
Sourcepub fn to_typed_value(self) -> TypedValue
pub fn to_typed_value(self) -> TypedValue
Convert this value to a TypedValue deterministically.
Each Value variant maps to exactly one Type variant,
so there is no inference or fallback - the mapping is deterministic.
§Example
use surreal_sync_core::{Value, Type};
let value = Value::Int32(42);
let typed = value.to_typed_value();
assert!(matches!(typed.sync_type, Type::Int32));
let value = Value::Text("hello".to_string());
let typed = value.to_typed_value();
assert!(matches!(typed.sync_type, Type::Text));