Skip to main content

Value

Enum Value 

Source
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

  1. Exact correspondence: Every Type variant has exactly one matching Value variant
  2. No inference: to_typed_value() is deterministic - no guessing or fallback
  3. Type metadata included: Variants like Char, VarChar, Decimal include their type parameters
  4. 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 }

Fields

§value: i8

The integer value

§width: u8

Display 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

§value: String

String representation of the decimal value

§precision: u8

Total number of digits

§scale: u8

Number of digits after decimal point

§

Char

Fixed-length character string → Type::Char { length }

Fields

§value: String

The string value

§length: u16

Maximum length

§

VarChar

Variable-length character string → Type::VarChar { length }

Fields

§value: String

The string value

§length: u16

Maximum 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 }

Fields

§elements: Vec<Value>

The array elements

§element_type: Box<Type>

Element type

§

Set

MySQL SET type → Type::Set { values }

Fields

§elements: Vec<String>

Selected values from the set

§allowed_values: Vec<String>

Allowed values in the set definition

§

Enum

Enumeration type → Type::Enum { values }

Fields

§value: String

The selected enum value

§allowed_values: Vec<String>

Allowed enum values

§

Geometry

Spatial/geometry type → Type::Geometry { geometry_type }

Fields

§data: GeometryData

Geometry data (WKB bytes or GeoJSON object)

§geometry_type: GeometryType

Specific geometry variant

§

Duration(Duration)

Duration type → Type::Duration

§

Thing

Record reference/link (e.g., SurrealDB Thing) → Type::Thing

Fields

§table: String

The target table/collection name

§id: Box<Value>

The record ID (can be string, int, uuid, etc.)

§

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.

Fields

§intended_type: Type

Intended column type (Date, Time, LocalDateTime, ZonedDateTime, …)

§source: Option<String>

Optional source literal for transforms/debugging, e.g. "0000-00-00 00:00:00"

Implementations§

Source§

impl Value

Source

pub fn tinyint(value: i8, width: u8) -> Self

Create a TinyInt value.

Source

pub fn decimal(value: impl Into<String>, precision: u8, scale: u8) -> Self

Create a Decimal value.

Source

pub fn char(value: impl Into<String>, length: u16) -> Self

Create a Char value.

Source

pub fn varchar(value: impl Into<String>, length: u16) -> Self

Create a VarChar value.

Source

pub fn array(elements: Vec<Value>, element_type: Type) -> Self

Create an Array value.

Source

pub fn set(elements: Vec<String>, allowed_values: Vec<String>) -> Self

Create a Set value.

Source

pub fn enum_value(value: impl Into<String>, allowed_values: Vec<String>) -> Self

Create an Enum value.

Source

pub fn geometry_geojson(data: Value, geometry_type: GeometryType) -> Self

Create a Geometry value from GeoJSON.

Source

pub fn json(value: Value) -> Self

Create a JSON value.

Source

pub fn jsonb(value: Value) -> Self

Create a JSONB value.

Source

pub fn zero_temporal(intended_type: Type, source: Option<String>) -> Self

Create a zero-temporal sentinel with the intended column type.

Source

pub fn canonical_zero_literal(intended_type: &Type) -> &'static str

Canonical MySQL-style zero literal for an intended temporal type.

Source

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.

Source

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

Source

pub fn is_zero_temporal_type(intended_type: &Type) -> bool

Whether intended_type may be used with Value::ZeroTemporal.

Source

pub fn is_null(&self) -> bool

Check if this value is null.

Source

pub fn is_zero_temporal(&self) -> bool

Check if this value is a zero-temporal sentinel.

Source

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

Try to get this value as a boolean.

Source

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

Try to get this value as an i32.

Source

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

Try to get this value as an i64.

Source

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

Try to get this value as an f64.

Source

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

Try to get this value as a string reference.

Source

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

Try to get this value as a byte slice.

Source

pub fn as_uuid(&self) -> Option<&Uuid>

Try to get this value as a UUID.

Source

pub fn as_ulid(&self) -> Option<&Ulid>

Try to get this value as a ULID.

Source

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

Try to get this value as a DateTime.

Source

pub fn as_array(&self) -> Option<&Vec<Value>>

Try to get this value as an array of elements.

Source

pub fn variant_name(&self) -> &'static str

Get a human-readable description of this value’s variant.

Source

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));
Source

pub fn to_type(&self) -> Type

Get the corresponding Type for this value.

This is a deterministic 1:1 mapping - no inference or fallback.

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<'de> Deserialize<'de> for Value

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Value

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl Serialize for Value

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq 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 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more