Skip to main content

Value

Enum Value 

Source
pub enum Value {
Show 15 variants Bool(Option<bool>), TinyInt(Option<i8>), SmallInt(Option<i16>), Int(Option<i32>), BigInt(Option<i64>), TinyUnsigned(Option<u8>), SmallUnsigned(Option<u16>), Unsigned(Option<u32>), BigUnsigned(Option<u64>), Float(Option<f32>), Double(Option<f64>), Char(Option<char>), String(Option<Box<String>>), Bytes(Option<Box<Vec<u8>>>), Array(ArrayType, Option<Box<Vec<Value>>>),
}
Expand description

Core value representation for SQL parameters.

This enum represents all possible SQL value types. The enum is designed to be size-optimized: larger types are boxed to maintain a consistent enum size of approximately one pointer width.

§Null Values

All variants use Option<T> to represent nullable values. A None value will be rendered as SQL NULL.

§Variant Naming Convention

Variant names align with common SQL type names:

VariantSQL TypeRust Type
Value::BoolBOOLEANbool
Value::TinyIntTINYINTi8
Value::SmallIntSMALLINTi16
Value::IntINTEGERi32
Value::BigIntBIGINTi64
Value::TinyUnsignedTINYINT UNSIGNEDu8
Value::SmallUnsignedSMALLINT UNSIGNEDu16
Value::UnsignedINTEGER UNSIGNEDu32
Value::BigUnsignedBIGINT UNSIGNEDu64
Value::FloatFLOATf32
Value::DoubleDOUBLEf64
Value::CharCHARchar
Value::StringVARCHAR/TEXTString
Value::BytesBLOB/BINARYVec<u8>

§Example

use reinhardt_query::Value;

// Integer types
let int_val = Value::Int(Some(42));
let null_int = Value::Int(None);
let bigint_val = Value::BigInt(Some(9223372036854775807i64));

// String type (boxed for size optimization)
let string_val = Value::String(Some(Box::new("hello".to_string())));

// Check for null
assert!(!int_val.is_null());
assert!(null_int.is_null());

// Convert to SQL literal
assert_eq!(int_val.to_sql_literal(), "42");
assert_eq!(null_int.to_sql_literal(), "NULL");

§Feature-Gated Types

Additional types are available with feature flags:

  • with-chrono: Date/time types (Value::ChronoDate, Value::ChronoTime, etc.)
  • with-uuid: UUID type (Value::Uuid)
  • with-json: JSON type (Value::Json)
  • with-rust_decimal: Decimal type (Value::Decimal)
  • with-bigdecimal: BigDecimal type (Value::BigDecimal)

Variants§

§

Bool(Option<bool>)

Boolean value

§

TinyInt(Option<i8>)

8-bit signed integer

§

SmallInt(Option<i16>)

16-bit signed integer

§

Int(Option<i32>)

32-bit signed integer

§

BigInt(Option<i64>)

64-bit signed integer

§

TinyUnsigned(Option<u8>)

8-bit unsigned integer

§

SmallUnsigned(Option<u16>)

16-bit unsigned integer

§

Unsigned(Option<u32>)

32-bit unsigned integer

§

BigUnsigned(Option<u64>)

64-bit unsigned integer

§

Float(Option<f32>)

32-bit floating point

§

Double(Option<f64>)

64-bit floating point

§

Char(Option<char>)

Single character

§

String(Option<Box<String>>)

String value (boxed)

§

Bytes(Option<Box<Vec<u8>>>)

Binary data (boxed)

§

Array(ArrayType, Option<Box<Vec<Value>>>)

Array of values with element type information

Implementations§

Source§

impl Value

Source

pub fn is_null(&self) -> bool

Returns true if this value is null.

§Example
use reinhardt_query::Value;

assert!(Value::Int(None).is_null());
assert!(!Value::Int(Some(42)).is_null());
Source§

impl Value

Source

pub fn to_sql_literal(&self) -> String

Convert this value to a SQL literal string suitable for inlining into a SQL statement.

This is used by QueryStatementBuilder::to_string() to produce SQL with values inlined (for debugging and non-parameterized use).

§Example
use reinhardt_query::Value;

assert_eq!(Value::Int(Some(42)).to_sql_literal(), "42");
assert_eq!(Value::Int(None).to_sql_literal(), "NULL");
assert_eq!(
    Value::String(Some(Box::new("hello".to_string()))).to_sql_literal(),
    "'hello'"
);
assert_eq!(
    Value::String(Some(Box::new("it's".to_string()))).to_sql_literal(),
    "'it''s'"
);

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, which is a null string.

Source§

impl From<&[u8]> for Value

Source§

fn from(v: &[u8]) -> Self

Converts to this type from the input type.
Source§

impl From<&str> for Value

Source§

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

Source§

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

Source§

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

Source§

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

Source§

fn into_value(self) -> Value

Converts this value into a Value.
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 · 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 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<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, 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.