Skip to main content

Value

Enum Value 

Source
#[non_exhaustive]
pub enum Value {
Show 16 variants Null, Bool(bool), I8(i8), I16(i16), I32(i32), I64(i64), U8(u8), U16(u16), U32(u32), U64(u64), F32(f32), F64(f64), Text(String), Bytes(Vec<u8>), Array(Vec<Value>), Custom(Arc<dyn CustomValue>),
}
Expand description

A bound argument.

keelson carries its own value enum rather than being generic over a driver’s parameter type. That keeps Expression free of any backend type parameter, and it means a built query’s arguments can be inspected — printed, compared, serialised — without a database in the loop.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Null

SQL NULL.

§

Bool(bool)

A boolean.

§

I8(i8)

An 8-bit signed integer.

§

I16(i16)

A 16-bit signed integer.

§

I32(i32)

A 32-bit signed integer.

§

I64(i64)

A 64-bit signed integer.

§

U8(u8)

An 8-bit unsigned integer.

§

U16(u16)

A 16-bit unsigned integer.

§

U32(u32)

A 32-bit unsigned integer.

§

U64(u64)

A 64-bit unsigned integer.

§

F32(f32)

A single-precision float.

§

F64(f64)

A double-precision float.

§

Text(String)

Character data.

§

Bytes(Vec<u8>)

Binary data — BYTEA, BLOB.

§

Array(Vec<Value>)

A homogeneous array, for dialects that have one (PostgreSQL).

§

Custom(Arc<dyn CustomValue>)

Escape hatch for dialect-specific types. Backends downcast through CustomValue::as_any.

Implementations§

Source§

impl Value

Source

pub fn array<T, I>(items: I) -> Value
where T: ToValue, I: IntoIterator<Item = T>,

Build a Value::Array from anything iterable.

There is deliberately no blanket ToValue for Vec<T>: it would collide with Vec<u8>, which must stay Value::Bytes so BYTEA/BLOB binds correctly. Arrays are therefore explicit.

Source

pub fn custom<C>(value: C) -> Value
where C: CustomValue,

Wrap a dialect-specific value.

Source

pub fn is_null(&self) -> bool

Whether this is Value::Null.

Source

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

The variant name, for error messages.

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<(), Error>

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

impl FromValue for Value

Source§

fn from_value(v: Value) -> Result<Value, Error>

Consume a Value and produce Self, or explain why not.
Source§

impl IntoExpr for Value

Source§

fn into_expr(self) -> Expr

Perform the conversion.
Source§

impl IntoExprList for Value

Source§

fn into_expr_list(self) -> Vec<Expr>

Perform the conversion.
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

Value serialises as the underlying scalar, never as a tagged enum.

This is what makes Vec<Value> comparable against a plain JSON array of arguments — Value::I32(100) becomes 100, not {"I32":100} — which is the shape the test suite compares against.

Source§

fn serialize<S>( &self, s: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

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

impl ToValue for Value

Source§

fn to_value(self) -> Value

Consume self and produce the argument to bind.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Value

§

impl !UnwindSafe for Value

§

impl Freeze for Value

§

impl Send for Value

§

impl Sync for Value

§

impl Unpin for Value

§

impl UnsafeUnpin 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.