Skip to main content

Value

Enum Value 

Source
pub enum Value {
Show 28 variants Empty(DataType), Bool(bool), Char(char), Int8(i8), Int16(i16), Int32(i32), Int64(i64), Int128(i128), UInt8(u8), UInt16(u16), UInt32(u32), UInt64(u64), UInt128(u128), IntSize(isize), UIntSize(usize), Float32(f32), Float64(f64), BigInteger(BigInt), BigDecimal(BigDecimal), String(String), Date(NaiveDate), Time(NaiveTime), DateTime(NaiveDateTime), Instant(DateTime<Utc>), Duration(Duration), Url(Url), StringMap(HashMap<String, String>), Json(Value),
}
Expand description

Single value container

Uses an enum to represent different types of values, providing type-safe value storage and access.

§Features

  • Zero-cost abstraction with compile-time type checking
  • Supports multiple basic data types
  • Provides two sets of APIs for type checking and type conversion
  • Automatic memory management

§Example

use qubit_value::Value;

// Create an integer value
let value = Value::Int32(42);
assert_eq!(value.get_int32().unwrap(), 42);

// Type conversion
let converted = value.to::<i64>().unwrap();
assert_eq!(converted, 42i64);

// String value
let text = Value::String("hello".to_string());
assert_eq!(text.get_string().unwrap(), "hello");

Variants§

§

Empty(DataType)

Empty value (has type but no value)

§

Bool(bool)

Boolean value

§

Char(char)

Character value

§

Int8(i8)

8-bit signed integer

§

Int16(i16)

16-bit signed integer

§

Int32(i32)

32-bit signed integer

§

Int64(i64)

64-bit signed integer

§

Int128(i128)

128-bit signed integer

§

UInt8(u8)

8-bit unsigned integer

§

UInt16(u16)

16-bit unsigned integer

§

UInt32(u32)

32-bit unsigned integer

§

UInt64(u64)

64-bit unsigned integer

§

UInt128(u128)

128-bit unsigned integer

§

IntSize(isize)

Platform-dependent signed integer (isize)

§

UIntSize(usize)

Platform-dependent unsigned integer (usize)

§

Float32(f32)

32-bit floating point number

§

Float64(f64)

64-bit floating point number

§

BigInteger(BigInt)

Big integer type

§

BigDecimal(BigDecimal)

Big decimal type

§

String(String)

String

§

Date(NaiveDate)

Date

§

Time(NaiveTime)

Time

§

DateTime(NaiveDateTime)

Date and time

§

Instant(DateTime<Utc>)

UTC instant

§

Duration(Duration)

Duration type (std::time::Duration)

§

Url(Url)

URL type (url::Url)

§

StringMap(HashMap<String, String>)

String map type (HashMap<String, String>)

§

Json(Value)

JSON value type (serde_json::Value)

Implementations§

Source§

impl Value

Unified getter generation macro

Supports two modes:

  1. copy: - For types implementing the Copy trait, directly returns the value
  2. ref: - For non-Copy types, returns a reference

§Documentation Comment Support

The macro automatically extracts preceding documentation comments, so you can add /// comments before macro invocations.

Source

pub fn new<T>(value: T) -> Self
where T: Into<Self>,

Generic constructor method

Creates a Value from any supported type, avoiding direct use of enum variants.

§Supported Generic Types

Value::new<T>(value) currently supports the following T:

  • bool
  • char
  • i8, i16, i32, i64, i128
  • u8, u16, u32, u64, u128
  • f32, f64
  • String, &str
  • NaiveDate, NaiveTime, NaiveDateTime, DateTime<Utc>
  • BigInt, BigDecimal
  • isize, usize
  • Duration
  • Url
  • HashMap<String, String>
  • serde_json::Value
§Type Parameters
  • T - The type of the value to wrap
§Returns

Returns a Value wrapping the given value

§Example
use qubit_value::Value;

// Basic types
let v = Value::new(42i32);
assert_eq!(v.get_int32().unwrap(), 42);

let v = Value::new(true);
assert_eq!(v.get_bool().unwrap(), true);

// String
let v = Value::new("hello".to_string());
assert_eq!(v.get_string().unwrap(), "hello");
Source

pub fn get<T>(&self) -> ValueResult<T>
where for<'a> T: TryFrom<&'a Self, Error = ValueError>,

Generic getter method.

Performs a strict typed read of the stored value as T.

get<T>() performs strict type matching. It does not do cross-type conversion.

For example, Value::Int32(42).get::<i64>() fails, while Value::Int32(42).to::<i64>() succeeds.

§Supported Generic Types

Value::get<T>() currently supports the following T:

  • bool
  • char
  • i8, i16, i32, i64, i128
  • u8, u16, u32, u64, u128
  • f32, f64
  • String
  • NaiveDate, NaiveTime, NaiveDateTime, DateTime<Utc>
  • BigInt, BigDecimal
  • isize, usize
  • Duration
  • Url
  • HashMap<String, String>
  • serde_json::Value
§Type Parameters
  • T - The target type to retrieve
§Returns

Returns the stored value when its type matches T.

§Errors

Returns ValueError::NoValue when the value is empty with the requested type, or ValueError::TypeMismatch when the stored type differs from T.

§Example
use qubit_value::Value;

let value = Value::Int32(42);

// Through type inference
let num: i32 = value.get().unwrap();
assert_eq!(num, 42);

// Explicitly specify type parameter
let num = value.get::<i32>().unwrap();
assert_eq!(num, 42);

// Different type
let text = Value::String("hello".to_string());
let s: String = text.get().unwrap();
assert_eq!(s, "hello");

// Boolean value
let flag = Value::Bool(true);
let b: bool = flag.get().unwrap();
assert_eq!(b, true);
Source

pub fn get_or<T>(&self, default: impl IntoValueDefault<T>) -> ValueResult<T>
where for<'a> T: TryFrom<&'a Self, Error = ValueError>,

Generic getter method with a default value.

Returns the supplied default only when this value is empty. Type mismatches and conversion errors are still returned as errors.

Source

pub fn to<T>(&self) -> ValueResult<T>
where for<'a> DataConverter<'a>: DataConvertTo<T>,

Generic conversion method

Converts the current value to the target type according to the shared value conversion rules.

§Supported Target Types And Source Variants

Value::to<T>() currently supports the following target types:

  • bool
    • Value::Bool
    • Value::Int8, Value::Int16, Value::Int32, Value::Int64, Value::Int128
    • Value::UInt8, Value::UInt16, Value::UInt32, Value::UInt64, Value::UInt128
    • Value::String, parsed as 1, 0, or ASCII case-insensitive true / false
  • char
    • Value::Char
  • i8
    • Value::Int8
    • Value::Bool
    • Value::Char
    • all integer variants
    • Value::Float32, Value::Float64
    • Value::String, parsed as i8
    • Value::BigInteger, Value::BigDecimal
  • i16
    • Value::Int16
    • Value::Bool
    • Value::Char
    • all integer variants
    • Value::Float32, Value::Float64
    • Value::String, parsed as i16
    • Value::BigInteger, Value::BigDecimal
  • i32
    • Value::Int32
    • Value::Bool
    • Value::Char
    • Value::Int8, Value::Int16, Value::Int64, Value::Int128
    • Value::UInt8, Value::UInt16, Value::UInt32, Value::UInt64, Value::UInt128
    • Value::Float32, Value::Float64
    • Value::String, parsed as i32
    • Value::BigInteger, Value::BigDecimal
  • i64
    • Value::Int64
    • Value::Bool
    • Value::Char
    • Value::Int8, Value::Int16, Value::Int32, Value::Int128
    • Value::UInt8, Value::UInt16, Value::UInt32, Value::UInt64, Value::UInt128
    • Value::Float32, Value::Float64
    • Value::String, parsed as i64
    • Value::BigInteger, Value::BigDecimal
  • i128
    • Value::Int128
    • Value::Bool
    • Value::Char
    • all integer variants
    • Value::Float32, Value::Float64
    • Value::String, parsed as i128
    • Value::BigInteger, Value::BigDecimal
  • u8
    • Value::UInt8
    • Value::Bool
    • Value::Char
    • Value::Int8, Value::Int16, Value::Int32, Value::Int64, Value::Int128
    • Value::UInt16, Value::UInt32, Value::UInt64, Value::UInt128
    • Value::String, parsed as u8
  • u16
    • Value::UInt8, Value::UInt16, Value::UInt32, Value::UInt64, Value::UInt128
    • Value::Bool
    • Value::Char
    • Value::Int8, Value::Int16, Value::Int32, Value::Int64, Value::Int128
    • Value::String, parsed as u16
  • u32
    • Value::UInt8, Value::UInt16, Value::UInt32, Value::UInt64, Value::UInt128
    • Value::Bool
    • Value::Char
    • Value::Int8, Value::Int16, Value::Int32, Value::Int64, Value::Int128
    • Value::String, parsed as u32
  • u64
    • Value::UInt8, Value::UInt16, Value::UInt32, Value::UInt64, Value::UInt128
    • Value::Bool
    • Value::Char
    • Value::Int8, Value::Int16, Value::Int32, Value::Int64, Value::Int128
    • Value::String, parsed as u64
  • u128
    • Value::UInt8, Value::UInt16, Value::UInt32, Value::UInt64, Value::UInt128
    • Value::Bool
    • Value::Char
    • Value::Int8, Value::Int16, Value::Int32, Value::Int64, Value::Int128
    • Value::String, parsed as u128
  • f32
    • Value::Float32, Value::Float64
    • Value::Bool
    • Value::Char
    • Value::Int8, Value::Int16, Value::Int32, Value::Int64, Value::Int128
    • Value::UInt8, Value::UInt16, Value::UInt32, Value::UInt64, Value::UInt128
    • Value::String, parsed as f32
    • Value::BigInteger, Value::BigDecimal
  • f64
    • Value::Float64
    • Value::Bool
    • Value::Char
    • Value::Int8, Value::Int16, Value::Int32, Value::Int64, Value::Int128
    • Value::UInt8, Value::UInt16, Value::UInt32, Value::UInt64, Value::UInt128
    • Value::Float32
    • Value::String, parsed as f64
    • Value::BigInteger, Value::BigDecimal
  • String
    • Value::String
    • Value::Bool, Value::Char
    • all integer and floating-point variants
    • Value::Date, Value::Time, Value::DateTime, Value::Instant
    • Value::BigInteger, Value::BigDecimal
    • Value::IntSize, Value::UIntSize
    • Value::Duration, formatted with the configured duration unit. The default conversion options use milliseconds and append the unit suffix, for example 1500ms.
    • Value::Url
    • Value::StringMap, serialized as JSON text
    • Value::Json, serialized as JSON text
  • NaiveDate
    • Value::Date
  • NaiveTime
    • Value::Time
  • NaiveDateTime
    • Value::DateTime
  • DateTime<Utc>
    • Value::Instant
  • BigInt
    • Value::BigInteger
  • BigDecimal
    • Value::BigDecimal
  • isize
    • Value::IntSize
    • Value::Bool
    • Value::Char
    • all integer variants
    • Value::Float32, Value::Float64
    • Value::String, parsed as isize
    • Value::BigInteger, Value::BigDecimal
  • usize
    • Value::UIntSize
    • Value::Bool
    • Value::Char
    • all integer variants
    • Value::String, parsed as usize
  • Duration
    • Value::Duration
    • integer variants and Value::BigInteger, interpreted in the configured duration unit
    • Value::String, parsed as duration text. Explicit suffixes ns, us, ms, s, m, h, and d are supported; text without a suffix uses the configured duration unit.
  • Url
    • Value::Url
    • Value::String, parsed as URL text
  • HashMap<String, String>
    • Value::StringMap
  • serde_json::Value
    • Value::Json
    • Value::String, parsed as JSON text
    • Value::StringMap, converted to a JSON object

Any target type not listed above is not supported by Value::to<T>().

§Type Parameters
  • T - The target type to convert to
§Returns

Returns the converted value on success, or an error if conversion is not supported or fails.

§Example
use qubit_value::Value;

let value = Value::Int32(42);

let num: i64 = value.to().unwrap();
assert_eq!(num, 42);

let text: String = value.to().unwrap();
assert_eq!(text, "42");
Source

pub fn to_or<T>(&self, default: impl IntoValueDefault<T>) -> ValueResult<T>
where for<'a> DataConverter<'a>: DataConvertTo<T>,

Converts this value to T, or returns default when it is empty.

Conversion failures from non-empty values are preserved.

Source

pub fn to_with<T>(&self, options: &DataConversionOptions) -> ValueResult<T>
where for<'a> DataConverter<'a>: DataConvertTo<T>,

Converts this value to T using the provided conversion options.

This method uses the shared qubit_datatype conversion layer directly, so options such as string trimming, blank string handling, and boolean aliases are applied consistently with other value containers.

§Type Parameters
  • T - The target type to convert to.
§Parameters
  • options - Conversion options forwarded to the shared converter.
§Returns

Returns the converted value on success.

§Errors

Returns a crate::ValueError when the value is missing, unsupported, or invalid for T under the provided options.

Source

pub fn to_or_with<T>( &self, default: impl IntoValueDefault<T>, options: &DataConversionOptions, ) -> ValueResult<T>
where for<'a> DataConverter<'a>: DataConvertTo<T>,

Converts this value to T using conversion options, or returns default when it is empty.

Conversion failures from non-empty values are preserved.

Source

pub fn set<T>(&mut self, value: T) -> ValueResult<()>
where T: Into<Self>,

Generic setter method

Replaces the current value with any supported input value.

This operation updates the stored type to T when needed. It does not perform runtime type-mismatch validation against the previous variant.

§Supported Generic Types

Value::set<T>(value) currently supports the following T:

  • bool
  • char
  • i8, i16, i32, i64, i128
  • u8, u16, u32, u64, u128
  • f32, f64
  • String, &str
  • NaiveDate, NaiveTime, NaiveDateTime, DateTime<Utc>
  • BigInt, BigDecimal
  • isize, usize
  • Duration
  • Url
  • HashMap<String, String>
  • serde_json::Value
§Type Parameters
  • T - Input type convertible into Value.
§Parameters
  • value - The value to set
§Returns

Always returns Ok(()) for supported input types. Unsupported input types fail to compile because they do not implement Into<Value>.

§Example
use qubit_datatype::DataType;
use qubit_value::Value;

let mut value = Value::Empty(DataType::Int32);

// Through type inference
value.set(42i32).unwrap();
assert_eq!(value.get_int32().unwrap(), 42);

// Explicitly specify type parameter
value.set::<i32>(100).unwrap();
assert_eq!(value.get_int32().unwrap(), 100);

// String type
let mut text = Value::Empty(DataType::String);
text.set("hello".to_string()).unwrap();
assert_eq!(text.get_string().unwrap(), "hello");
Source

pub fn data_type(&self) -> DataType

Get the data type of the value

§Returns

Returns the data type corresponding to this value

§Example
use qubit_datatype::DataType;
use qubit_value::Value;

let value = Value::Int32(42);
assert_eq!(value.data_type(), DataType::Int32);

let empty = Value::Empty(DataType::String);
assert_eq!(empty.data_type(), DataType::String);
Source

pub fn is_empty(&self) -> bool

Check if the value is empty

§Returns

Returns true if the value is empty

§Example
use qubit_datatype::DataType;
use qubit_value::Value;

let value = Value::Int32(42);
assert!(!value.is_empty());

let empty = Value::Empty(DataType::String);
assert!(empty.is_empty());
Source

pub fn clear(&mut self)

Clear the value while preserving the type

Sets the current value to empty but retains its data type.

§Example
use qubit_datatype::DataType;
use qubit_value::Value;

let mut value = Value::Int32(42);
value.clear();
assert!(value.is_empty());
assert_eq!(value.data_type(), DataType::Int32);
Source

pub fn set_type(&mut self, data_type: DataType)

Set the data type

If the new type differs from the current type, clears the value and sets the new type.

§Parameters
  • data_type - The data type to set
§Example
use qubit_datatype::DataType;
use qubit_value::Value;

let mut value = Value::Int32(42);
value.set_type(DataType::String);
assert!(value.is_empty());
assert_eq!(value.data_type(), DataType::String);
Source§

impl Value

Source

pub fn get_bool(&self) -> ValueResult<bool>

Get boolean value

§Returns

If types match, returns the boolean value; see # Errors.

§Example
use qubit_value::Value;

let value = Value::Bool(true);
assert_eq!(value.get_bool().unwrap(), true);
§Errors

Returns ValueError::NoValue when the value is empty with the requested type, or ValueError::TypeMismatch when the stored data type differs.

Source

pub fn get_char(&self) -> ValueResult<char>

Get character value

§Returns

If types match, returns the character value; see # Errors.

§Example
use qubit_value::Value;

let value = Value::Char('A');
assert_eq!(value.get_char().unwrap(), 'A');
§Errors

Returns ValueError::NoValue when the value is empty with the requested type, or ValueError::TypeMismatch when the stored data type differs.

Source

pub fn get_int8(&self) -> ValueResult<i8>

Get int8 value

§Returns

If types match, returns the int8 value; see # Errors.

§Errors

Returns ValueError::NoValue when the value is empty with the requested type, or ValueError::TypeMismatch when the stored data type differs.

Source

pub fn get_int16(&self) -> ValueResult<i16>

Get int16 value

§Returns

If types match, returns the int16 value; see # Errors.

§Errors

Returns ValueError::NoValue when the value is empty with the requested type, or ValueError::TypeMismatch when the stored data type differs.

Source

pub fn get_int32(&self) -> ValueResult<i32>

Get int32 value

§Returns

If types match, returns the int32 value; see # Errors.

§Errors

Returns ValueError::NoValue when the value is empty with the requested type, or ValueError::TypeMismatch when the stored data type differs.

Source

pub fn get_int64(&self) -> ValueResult<i64>

Get int64 value

§Returns

If types match, returns the int64 value; see # Errors.

§Errors

Returns ValueError::NoValue when the value is empty with the requested type, or ValueError::TypeMismatch when the stored data type differs.

Source

pub fn get_int128(&self) -> ValueResult<i128>

Get int128 value

§Returns

If types match, returns the int128 value; see # Errors.

§Errors

Returns ValueError::NoValue when the value is empty with the requested type, or ValueError::TypeMismatch when the stored data type differs.

Source

pub fn get_uint8(&self) -> ValueResult<u8>

Get uint8 value

§Returns

If types match, returns the uint8 value; see # Errors.

§Errors

Returns ValueError::NoValue when the value is empty with the requested type, or ValueError::TypeMismatch when the stored data type differs.

Source

pub fn get_uint16(&self) -> ValueResult<u16>

Get uint16 value

§Returns

If types match, returns the uint16 value; see # Errors.

§Errors

Returns ValueError::NoValue when the value is empty with the requested type, or ValueError::TypeMismatch when the stored data type differs.

Source

pub fn get_uint32(&self) -> ValueResult<u32>

Get uint32 value

§Returns

If types match, returns the uint32 value; see # Errors.

§Errors

Returns ValueError::NoValue when the value is empty with the requested type, or ValueError::TypeMismatch when the stored data type differs.

Source

pub fn get_uint64(&self) -> ValueResult<u64>

Get uint64 value

§Returns

If types match, returns the uint64 value; see # Errors.

§Errors

Returns ValueError::NoValue when the value is empty with the requested type, or ValueError::TypeMismatch when the stored data type differs.

Source

pub fn get_uint128(&self) -> ValueResult<u128>

Get uint128 value

§Returns

If types match, returns the uint128 value; see # Errors.

§Errors

Returns ValueError::NoValue when the value is empty with the requested type, or ValueError::TypeMismatch when the stored data type differs.

Source

pub fn get_float32(&self) -> ValueResult<f32>

Get float32 value

§Returns

If types match, returns the float32 value; see # Errors.

§Errors

Returns ValueError::NoValue when the value is empty with the requested type, or ValueError::TypeMismatch when the stored data type differs.

Source

pub fn get_float64(&self) -> ValueResult<f64>

Get float64 value

§Returns

If types match, returns the float64 value; see # Errors.

§Errors

Returns ValueError::NoValue when the value is empty with the requested type, or ValueError::TypeMismatch when the stored data type differs.

Source

pub fn get_string(&self) -> ValueResult<&str>

Get string reference

§Returns

If types match, returns a reference to the string; see # Errors.

§Example
use qubit_value::Value;

let value = Value::String("hello".to_string());
assert_eq!(value.get_string().unwrap(), "hello");
§Errors

Returns ValueError::NoValue when the value is empty with the requested type, or ValueError::TypeMismatch when the stored data type differs.

Source

pub fn get_date(&self) -> ValueResult<NaiveDate>

Get date value

§Returns

If types match, returns the date value; see # Errors.

§Errors

Returns ValueError::NoValue when the value is empty with the requested type, or ValueError::TypeMismatch when the stored data type differs.

Source

pub fn get_time(&self) -> ValueResult<NaiveTime>

Get time value

§Returns

If types match, returns the time value; see # Errors.

§Errors

Returns ValueError::NoValue when the value is empty with the requested type, or ValueError::TypeMismatch when the stored data type differs.

Source

pub fn get_datetime(&self) -> ValueResult<NaiveDateTime>

Get datetime value

§Returns

If types match, returns the datetime value; see # Errors.

§Errors

Returns ValueError::NoValue when the value is empty with the requested type, or ValueError::TypeMismatch when the stored data type differs.

Source

pub fn get_instant(&self) -> ValueResult<DateTime<Utc>>

Get UTC instant value

§Returns

If types match, returns the UTC instant value; see # Errors.

§Errors

Returns ValueError::NoValue when the value is empty with the requested type, or ValueError::TypeMismatch when the stored data type differs.

Source

pub fn get_biginteger(&self) -> ValueResult<BigInt>

Get big integer value.

This method returns a cloned BigInt. Use Value::get_biginteger_ref to borrow the stored value without cloning.

§Returns

If types match, returns the big integer value; see # Errors.

§Example
use qubit_value::Value;
use num_bigint::BigInt;

let value = Value::BigInteger(BigInt::from(123456789));
assert_eq!(value.get_biginteger().unwrap(), BigInt::from(123456789));
§Errors

Returns ValueError::NoValue when the value is empty with the requested type, or ValueError::TypeMismatch when the stored data type differs.

Source

pub fn get_bigdecimal(&self) -> ValueResult<BigDecimal>

Get big decimal value.

This method returns a cloned BigDecimal. Use Value::get_bigdecimal_ref to borrow the stored value without cloning.

§Returns

If types match, returns the big decimal value; see # Errors.

§Example
use std::str::FromStr;

use bigdecimal::BigDecimal;
use qubit_value::Value;

let bd = BigDecimal::from_str("123.456").unwrap();
let value = Value::BigDecimal(bd.clone());
assert_eq!(value.get_bigdecimal().unwrap(), bd);
§Errors

Returns ValueError::NoValue when the value is empty with the requested type, or ValueError::TypeMismatch when the stored data type differs.

Source

pub fn set_bool(&mut self, value: bool) -> ValueResult<()>

Set boolean value

§Parameters
  • value - The boolean value to set
§Returns

Always returns Ok(()) for this supported setter.

§Example
use qubit_datatype::DataType;
use qubit_value::Value;

let mut value = Value::Empty(DataType::Bool);
value.set_bool(true).unwrap();
assert_eq!(value.get_bool().unwrap(), true);
Source

pub fn set_char(&mut self, value: char) -> ValueResult<()>

Set character value

§Parameters
  • value - The character value to set
§Returns

Always returns Ok(()) for this supported setter.

Source

pub fn set_int8(&mut self, value: i8) -> ValueResult<()>

Set int8 value

§Parameters
  • value - The int8 value to set
§Returns

Always returns Ok(()) for this supported setter.

Source

pub fn set_int16(&mut self, value: i16) -> ValueResult<()>

Set int16 value

§Parameters
  • value - The int16 value to set
§Returns

Always returns Ok(()) for this supported setter.

Source

pub fn set_int32(&mut self, value: i32) -> ValueResult<()>

Set int32 value

§Parameters
  • value - The int32 value to set
§Returns

Always returns Ok(()) for this supported setter.

Source

pub fn set_int64(&mut self, value: i64) -> ValueResult<()>

Set int64 value

§Parameters
  • value - The int64 value to set
§Returns

Always returns Ok(()) for this supported setter.

Source

pub fn set_int128(&mut self, value: i128) -> ValueResult<()>

Set int128 value

§Parameters
  • value - The int128 value to set
§Returns

Always returns Ok(()) for this supported setter.

Source

pub fn set_uint8(&mut self, value: u8) -> ValueResult<()>

Set uint8 value

§Parameters
  • value - The uint8 value to set
§Returns

Always returns Ok(()) for this supported setter.

Source

pub fn set_uint16(&mut self, value: u16) -> ValueResult<()>

Set uint16 value

§Parameters
  • value - The uint16 value to set
§Returns

Always returns Ok(()) for this supported setter.

Source

pub fn set_uint32(&mut self, value: u32) -> ValueResult<()>

Set uint32 value

§Parameters
  • value - The uint32 value to set
§Returns

Always returns Ok(()) for this supported setter.

Source

pub fn set_uint64(&mut self, value: u64) -> ValueResult<()>

Set uint64 value

§Parameters
  • value - The uint64 value to set
§Returns

Always returns Ok(()) for this supported setter.

Source

pub fn set_uint128(&mut self, value: u128) -> ValueResult<()>

Set uint128 value

§Parameters
  • value - The uint128 value to set
§Returns

Always returns Ok(()) for this supported setter.

Source

pub fn set_float32(&mut self, value: f32) -> ValueResult<()>

Set float32 value

§Parameters
  • value - The float32 value to set
§Returns

Always returns Ok(()) for this supported setter.

Source

pub fn set_float64(&mut self, value: f64) -> ValueResult<()>

Set float64 value

§Parameters
  • value - The float64 value to set
§Returns

Always returns Ok(()) for this supported setter.

Source

pub fn set_string(&mut self, value: String) -> ValueResult<()>

Set string value

§Parameters
  • value - The string value to set
§Returns

Always returns Ok(()) for this supported setter.

§Example
use qubit_datatype::DataType;
use qubit_value::Value;

let mut value = Value::Empty(DataType::String);
value.set_string("hello".to_string()).unwrap();
assert_eq!(value.get_string().unwrap(), "hello");
Source

pub fn set_date(&mut self, value: NaiveDate) -> ValueResult<()>

Set date value

§Parameters
  • value - The date value to set
§Returns

Always returns Ok(()) for this supported setter.

Source

pub fn set_time(&mut self, value: NaiveTime) -> ValueResult<()>

Set time value

§Parameters
  • value - The time value to set
§Returns

Always returns Ok(()) for this supported setter.

Source

pub fn set_datetime(&mut self, value: NaiveDateTime) -> ValueResult<()>

Set datetime value

§Parameters
  • value - The datetime value to set
§Returns

Always returns Ok(()) for this supported setter.

Source

pub fn set_instant(&mut self, value: DateTime<Utc>) -> ValueResult<()>

Set UTC instant value

§Parameters
  • value - The UTC instant value to set
§Returns

Always returns Ok(()) for this supported setter.

Source

pub fn set_biginteger(&mut self, value: BigInt) -> ValueResult<()>

Set big integer value

§Parameters
  • value - The big integer value to set
§Returns

Always returns Ok(()) for this supported setter.

§Example
use num_bigint::BigInt;
use qubit_datatype::DataType;
use qubit_value::Value;

let mut value = Value::Empty(DataType::BigInteger);
value.set_biginteger(BigInt::from(123456789)).unwrap();
assert_eq!(value.get_biginteger().unwrap(), BigInt::from(123456789));
Source

pub fn set_bigdecimal(&mut self, value: BigDecimal) -> ValueResult<()>

Set big decimal value

§Parameters
  • value - The big decimal value to set
§Returns

Always returns Ok(()) for this supported setter.

§Example
use std::str::FromStr;

use bigdecimal::BigDecimal;
use qubit_datatype::DataType;
use qubit_value::Value;

let mut value = Value::Empty(DataType::BigDecimal);
let bd = BigDecimal::from_str("123.456").unwrap();
value.set_bigdecimal(bd.clone()).unwrap();
assert_eq!(value.get_bigdecimal().unwrap(), bd);
Source

pub fn get_intsize(&self) -> ValueResult<isize>

Get isize value

§Returns

If types match, returns the isize value; see # Errors.

§Errors

Returns ValueError::NoValue when the value is empty with the requested type, or ValueError::TypeMismatch when the stored data type differs.

Source

pub fn get_uintsize(&self) -> ValueResult<usize>

Get usize value

§Returns

If types match, returns the usize value; see # Errors.

§Errors

Returns ValueError::NoValue when the value is empty with the requested type, or ValueError::TypeMismatch when the stored data type differs.

Source

pub fn get_duration(&self) -> ValueResult<Duration>

Get Duration value

§Returns

If types match, returns the Duration value; see # Errors.

§Errors

Returns ValueError::NoValue when the value is empty with the requested type, or ValueError::TypeMismatch when the stored data type differs.

Source

pub fn get_url(&self) -> ValueResult<Url>

Get URL value.

This method returns a cloned Url. Use Value::get_url_ref to borrow the stored value without cloning.

§Returns

If types match, returns the URL value; see # Errors.

§Errors

Returns ValueError::NoValue when the value is empty with the requested type, or ValueError::TypeMismatch when the stored data type differs.

Source

pub fn get_string_map(&self) -> ValueResult<HashMap<String, String>>

Get string map value.

This method returns a cloned HashMap<String, String>. Use Value::get_string_map_ref to borrow the stored value without cloning.

§Returns

If types match, returns the string map value; see # Errors.

§Errors

Returns ValueError::NoValue when the value is empty with the requested type, or ValueError::TypeMismatch when the stored data type differs.

Source

pub fn get_json(&self) -> ValueResult<Value>

Get JSON value.

This method returns a cloned serde_json::Value. Use Value::get_json_ref to borrow the stored value without cloning.

§Returns

If types match, returns the JSON value; see # Errors.

§Errors

Returns ValueError::NoValue when the value is empty with the requested type, or ValueError::TypeMismatch when the stored data type differs.

Source

pub fn get_biginteger_ref(&self) -> ValueResult<&BigInt>

Borrow the inner BigInt without cloning.

§Errors

Returns ValueError::NoValue when the value is empty with DataType::BigInteger, or ValueError::TypeMismatch when the stored data type differs.

Source

pub fn get_bigdecimal_ref(&self) -> ValueResult<&BigDecimal>

Borrow the inner BigDecimal without cloning.

§Errors

Returns ValueError::NoValue when the value is empty with DataType::BigDecimal, or ValueError::TypeMismatch when the stored data type differs.

Source

pub fn get_url_ref(&self) -> ValueResult<&Url>

Borrow the inner Url without cloning.

§Errors

Returns ValueError::NoValue when the value is empty with DataType::Url, or ValueError::TypeMismatch when the stored data type differs.

Source

pub fn get_string_map_ref(&self) -> ValueResult<&HashMap<String, String>>

Borrow the inner HashMap<String, String> without cloning.

§Errors

Returns ValueError::NoValue when the value is empty with DataType::StringMap, or ValueError::TypeMismatch when the stored data type differs.

Source

pub fn get_json_ref(&self) -> ValueResult<&Value>

Borrow the inner JSON value without cloning.

§Errors

Returns ValueError::NoValue when the value is empty with DataType::Json, or ValueError::TypeMismatch when the stored data type differs.

Source

pub fn set_intsize(&mut self, value: isize) -> ValueResult<()>

Set isize value

Source

pub fn set_uintsize(&mut self, value: usize) -> ValueResult<()>

Set usize value

Source

pub fn set_duration(&mut self, value: Duration) -> ValueResult<()>

Set Duration value

Source

pub fn set_url(&mut self, value: Url) -> ValueResult<()>

Set Url value

Source

pub fn set_string_map( &mut self, value: HashMap<String, String>, ) -> ValueResult<()>

Set StringMap value

Source

pub fn set_json(&mut self, value: Value) -> ValueResult<()>

Set Json value

Source

pub fn from_json_value(json: Value) -> Self

Create a Value from a serde_json::Value.

§Parameters
  • json - The JSON value to wrap.
§Returns

Returns a Value::Json wrapping the given JSON value.

Source

pub fn from_serializable<T: Serialize>(value: &T) -> ValueResult<Self>

Create a Value from any serializable value by converting it to JSON.

§Type Parameters
  • T - Any type implementing Serialize.
§Parameters
  • value - The value to serialize into JSON.
§Returns

Returns Ok(Value::Json(...)) on success, or an error if serialization fails.

Source

pub fn deserialize_json<T: DeserializeOwned>(&self) -> ValueResult<T>

Deserialize the inner JSON value into a target type.

Only works when self is Value::Json(...).

§Type Parameters
  • T - The target type implementing DeserializeOwned.
§Returns

Returns Ok(T) on success.

§Errors

Returns ValueError::NoValue when this value is Empty(Json), ValueError::TypeMismatch when this value has a non-JSON data type, or ValueError::JsonDeserializationError when JSON deserialization fails.

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

Source§

fn default() -> Self

Returns the “default value” for a type. 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 From<&str> for Value

Source§

fn from(value: &str) -> Self

Converts to this type from the input type.
Source§

impl From<BigDecimal> for Value

Source§

fn from(value: BigDecimal) -> Self

Converts to this type from the input type.
Source§

impl From<BigInt> for Value

Source§

fn from(value: BigInt) -> Self

Converts to this type from the input type.
Source§

impl From<DateTime<Utc>> for Value

Source§

fn from(value: DateTime<Utc>) -> Self

Converts to this type from the input type.
Source§

impl From<Duration> for Value

Source§

fn from(value: Duration) -> Self

Converts to this type from the input type.
Source§

impl From<HashMap<String, String>> for Value

Source§

fn from(value: HashMap<String, String>) -> Self

Converts to this type from the input type.
Source§

impl From<NaiveDate> for Value

Source§

fn from(value: NaiveDate) -> Self

Converts to this type from the input type.
Source§

impl From<NaiveDateTime> for Value

Source§

fn from(value: NaiveDateTime) -> Self

Converts to this type from the input type.
Source§

impl From<NaiveTime> for Value

Source§

fn from(value: NaiveTime) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Value

Source§

fn from(value: String) -> Self

Converts to this type from the input type.
Source§

impl From<Url> for Value

Source§

fn from(value: Url) -> Self

Converts to this type from the input type.
Source§

impl From<Value> for MultiValues

Source§

fn from(value: Value) -> Self

Converts to this type from the input type.
Source§

impl From<Value> for Value

Source§

fn from(value: Value) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for Value

Source§

fn from(value: bool) -> Self

Converts to this type from the input type.
Source§

impl From<char> for Value

Source§

fn from(value: char) -> Self

Converts to this type from the input type.
Source§

impl From<f32> for Value

Source§

fn from(value: f32) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for Value

Source§

fn from(value: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i128> for Value

Source§

fn from(value: i128) -> Self

Converts to this type from the input type.
Source§

impl From<i16> for Value

Source§

fn from(value: i16) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for Value

Source§

fn from(value: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for Value

Source§

fn from(value: i64) -> Self

Converts to this type from the input type.
Source§

impl From<i8> for Value

Source§

fn from(value: i8) -> Self

Converts to this type from the input type.
Source§

impl From<isize> for Value

Source§

fn from(value: isize) -> Self

Converts to this type from the input type.
Source§

impl From<u128> for Value

Source§

fn from(value: u128) -> Self

Converts to this type from the input type.
Source§

impl From<u16> for Value

Source§

fn from(value: u16) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for Value

Source§

fn from(value: u32) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for Value

Source§

fn from(value: u64) -> Self

Converts to this type from the input type.
Source§

impl From<u8> for Value

Source§

fn from(value: u8) -> Self

Converts to this type from the input type.
Source§

impl From<usize> for Value

Source§

fn from(value: usize) -> 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 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 TryFrom<&Value> for BigDecimal

Source§

type Error = ValueError

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> ValueResult<BigDecimal>

Performs the conversion.
Source§

impl TryFrom<&Value> for BigInt

Source§

type Error = ValueError

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> ValueResult<BigInt>

Performs the conversion.
Source§

impl TryFrom<&Value> for DateTime<Utc>

Source§

type Error = ValueError

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> ValueResult<DateTime<Utc>>

Performs the conversion.
Source§

impl TryFrom<&Value> for Duration

Source§

type Error = ValueError

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> ValueResult<Duration>

Performs the conversion.
Source§

impl TryFrom<&Value> for HashMap<String, String>

Source§

type Error = ValueError

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> ValueResult<HashMap<String, String>>

Performs the conversion.
Source§

impl TryFrom<&Value> for NaiveDate

Source§

type Error = ValueError

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> ValueResult<NaiveDate>

Performs the conversion.
Source§

impl TryFrom<&Value> for NaiveDateTime

Source§

type Error = ValueError

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> ValueResult<NaiveDateTime>

Performs the conversion.
Source§

impl TryFrom<&Value> for NaiveTime

Source§

type Error = ValueError

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> ValueResult<NaiveTime>

Performs the conversion.
Source§

impl TryFrom<&Value> for String

String specialization because Value::get_string() returns &str.

Source§

type Error = ValueError

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> ValueResult<String>

Performs the conversion.
Source§

impl TryFrom<&Value> for Url

Source§

type Error = ValueError

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> ValueResult<Url>

Performs the conversion.
Source§

impl TryFrom<&Value> for Value

Source§

type Error = ValueError

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> ValueResult<Value>

Performs the conversion.
Source§

impl TryFrom<&Value> for bool

Source§

type Error = ValueError

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> ValueResult<bool>

Performs the conversion.
Source§

impl TryFrom<&Value> for char

Source§

type Error = ValueError

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> ValueResult<char>

Performs the conversion.
Source§

impl TryFrom<&Value> for f32

Source§

type Error = ValueError

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> ValueResult<f32>

Performs the conversion.
Source§

impl TryFrom<&Value> for f64

Source§

type Error = ValueError

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> ValueResult<f64>

Performs the conversion.
Source§

impl TryFrom<&Value> for i128

Source§

type Error = ValueError

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> ValueResult<i128>

Performs the conversion.
Source§

impl TryFrom<&Value> for i16

Source§

type Error = ValueError

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> ValueResult<i16>

Performs the conversion.
Source§

impl TryFrom<&Value> for i32

Source§

type Error = ValueError

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> ValueResult<i32>

Performs the conversion.
Source§

impl TryFrom<&Value> for i64

Source§

type Error = ValueError

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> ValueResult<i64>

Performs the conversion.
Source§

impl TryFrom<&Value> for i8

Source§

type Error = ValueError

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> ValueResult<i8>

Performs the conversion.
Source§

impl TryFrom<&Value> for isize

Source§

type Error = ValueError

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> ValueResult<isize>

Performs the conversion.
Source§

impl TryFrom<&Value> for u128

Source§

type Error = ValueError

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> ValueResult<u128>

Performs the conversion.
Source§

impl TryFrom<&Value> for u16

Source§

type Error = ValueError

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> ValueResult<u16>

Performs the conversion.
Source§

impl TryFrom<&Value> for u32

Source§

type Error = ValueError

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> ValueResult<u32>

Performs the conversion.
Source§

impl TryFrom<&Value> for u64

Source§

type Error = ValueError

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> ValueResult<u64>

Performs the conversion.
Source§

impl TryFrom<&Value> for u8

Source§

type Error = ValueError

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> ValueResult<u8>

Performs the conversion.
Source§

impl TryFrom<&Value> for usize

Source§

type Error = ValueError

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> ValueResult<usize>

Performs the conversion.
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> IntoValueDefault<T> for T

Source§

fn into_value_default(self) -> T

Converts this argument into the default value.
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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,