Skip to main content

Value

Enum Value 

Source
pub enum Value {
Show 14 variants Null, Bool(bool), I64(i64), F64(f64), Text(String), Blob(Vec<u8>), Timestamp(i64), Date(i32), Time(i64), Uuid(u128), Json(String), Decimal(String), Array(Vec<Value>), TypedArray { element_type: ArrayElementType, values: Vec<Value>, },
}
Expand description

A single SQL value returned from or passed to a query.

Covers both the basic scalar types common to all databases and extended types for dates, timestamps, UUIDs, JSON, exact decimals, and arrays.

Variants§

§

Null

SQL NULL.

§

Bool(bool)

Boolean value.

§

I64(i64)

64-bit signed integer.

§

F64(f64)

64-bit floating-point number.

§

Text(String)

UTF-8 text string.

§

Blob(Vec<u8>)

Raw binary data.

§

Timestamp(i64)

Unix timestamp with microsecond precision (microseconds since epoch, UTC). Maps to SQL TIMESTAMP / TIMESTAMPTZ.

§

Date(i32)

Date-only value as days since Unix epoch (1970-01-01). Maps to SQL DATE.

§

Time(i64)

Time-of-day value as microseconds since midnight. Maps to SQL TIME.

§

Uuid(u128)

UUID stored as a 128-bit unsigned integer. Maps to SQL UUID.

§

Json(String)

JSON or JSONB data stored as a UTF-8 string. Maps to SQL JSON / JSONB.

§

Decimal(String)

Exact decimal stored as a string representation (e.g. "123.456"). Using a string avoids introducing a big-decimal dependency at the core level while preserving exact precision. Maps to SQL NUMERIC / DECIMAL.

§

Array(Vec<Value>)

Ordered array of values (e.g. Postgres INTEGER[], TEXT[]).

§

TypedArray

Like Value::Array but also carries the nominal element type returned by the backend (e.g. PostgreSQL int4[]TypedArray { element_type: Int4, .. }).

Fields

§element_type: ArrayElementType

The nominal SQL element type of this array.

§values: Vec<Value>

The array elements.

Implementations§

Source§

impl Value

Source

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

Returns the human-readable type name of this value variant.

Source

pub fn is_null(&self) -> bool

Returns true if this value is Value::Null.

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

Source§

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

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

impl<'a> From<&'a Value> for BorrowedValue<'a>

Source§

fn from(v: &'a Value) -> Self

Borrow a Value as a BorrowedValue with zero allocation.

Text, Blob, Json, and Decimal borrow from the owned Value. Array borrows from a freshly-allocated intermediate Vec of BorrowedValues; use BorrowedValue::to_owned to get back an owned Value when needed.

Source§

impl From<&str> for Value

Source§

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

Source§

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

Source§

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

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 (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
Source§

impl StructuralPartialEq for Value

Source§

impl ToSqlValue for Value

Allow a Value to be used directly as a SQL parameter.

This enables fan-out helpers (e.g. MultiConnection) to collect parameter snapshots as Vec<Value> and pass them back to Connection::execute / Connection::query without an intermediate conversion step.

Source§

fn to_value(&self) -> Value

Convert self into a 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<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> 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> 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.