pub enum Value {
Null,
Bool(bool),
Int(i64),
Float(f64),
Text(SmartStr),
Array(Arc<[Value]>),
Object(Arc<IndexMap<Key, Value>>),
Binary(Arc<[u8]>),
}Expand description
Unified runtime representation for all parameter values.
This enum covers all possible value types that parameters can hold.
Collections use Arc for cheap cloning and thread-safe sharing.
§Examples
use paramdef::core::Value;
// Primitive values
let null = Value::Null;
let boolean = Value::Bool(true);
let integer = Value::Int(42);
let float = Value::Float(3.14);
let text = Value::text("hello");
// Type checking
assert!(null.is_null());
assert!(boolean.is_bool());
assert_eq!(integer.as_int(), Some(42));Variants§
Null
Absence of a value.
Bool(bool)
Boolean value.
Int(i64)
64-bit signed integer.
Float(f64)
64-bit floating point.
Text(SmartStr)
Text string using stack-optimized storage.
Array(Arc<[Value]>)
Ordered array of values.
Object(Arc<IndexMap<Key, Value>>)
Key-value object with insertion-order preservation.
Uses IndexMap to maintain the order in which fields were inserted,
providing consistent serialization and iteration order.
Binary(Arc<[u8]>)
Binary data.
Implementations§
Source§impl Value
impl Value
Source§impl Value
impl Value
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if this value is considered empty.
Nullis empty- Empty string is empty
- Empty array is empty
- Empty object is empty
- Empty binary is empty
§Examples
use paramdef::core::Value;
assert!(Value::Null.is_empty());
assert!(Value::text("").is_empty());
assert!(Value::array([]).is_empty());
assert!(!Value::text("hello").is_empty());Sourcepub const fn type_name(&self) -> &'static str
pub const fn type_name(&self) -> &'static str
Returns the type name as a string.
§Examples
use paramdef::core::Value;
assert_eq!(Value::Null.type_name(), "null");
assert_eq!(Value::Bool(true).type_name(), "bool");
assert_eq!(Value::Int(42).type_name(), "int");
assert_eq!(Value::text("hello").type_name(), "text");Source§impl Value
impl Value
Sourcepub fn text(s: impl Into<SmartStr>) -> Self
pub fn text(s: impl Into<SmartStr>) -> Self
Creates a text value from a string.
§Examples
use paramdef::core::Value;
let value = Value::text("hello");
assert_eq!(value.as_text(), Some("hello"));Sourcepub fn array(values: impl IntoIterator<Item = Value>) -> Self
pub fn array(values: impl IntoIterator<Item = Value>) -> Self
Creates an array value from an iterator.
Uses the iterator’s size_hint() to pre-allocate the Vec,
avoiding reallocation during construction.
§Examples
use paramdef::core::Value;
let value = Value::array([Value::Int(1), Value::Int(2), Value::Int(3)]);
assert_eq!(value.as_array().map(|a| a.len()), Some(3));Sourcepub fn array_with_capacity(
capacity: usize,
values: impl IntoIterator<Item = Value>,
) -> Self
pub fn array_with_capacity( capacity: usize, values: impl IntoIterator<Item = Value>, ) -> Self
Creates an array value with pre-allocated capacity.
Use this when you know the number of elements in advance
to avoid reallocation. For dynamic sizes, use Value::array which
uses the iterator’s size_hint().
§Examples
use paramdef::core::Value;
// Pre-allocate for 1000 elements
let mut values = Vec::with_capacity(1000);
for i in 0..1000 {
values.push(Value::Int(i));
}
let value = Value::array_with_capacity(1000, values);Sourcepub fn object(pairs: impl IntoIterator<Item = (impl Into<Key>, Value)>) -> Self
pub fn object(pairs: impl IntoIterator<Item = (impl Into<Key>, Value)>) -> Self
Creates an object value from key-value pairs.
Uses the iterator’s size_hint() to pre-allocate the IndexMap,
avoiding rehashing during construction. Field order is preserved.
§Examples
use paramdef::core::Value;
let value = Value::object([
("name", Value::text("Alice")),
("age", Value::Int(30)),
]);Sourcepub fn object_with_capacity(
capacity: usize,
pairs: impl IntoIterator<Item = (impl Into<Key>, Value)>,
) -> Self
pub fn object_with_capacity( capacity: usize, pairs: impl IntoIterator<Item = (impl Into<Key>, Value)>, ) -> Self
Creates an object value with pre-allocated capacity.
Use this when you know the number of key-value pairs in advance
to avoid rehashing. For dynamic sizes, use Value::object which
uses the iterator’s size_hint(). Field order is preserved.
§Examples
use paramdef::core::Value;
// Pre-allocate for 100 entries
let mut pairs = Vec::with_capacity(100);
for i in 0..100 {
pairs.push((format!("key_{i}"), Value::Int(i)));
}
let value = Value::object_with_capacity(100, pairs);Sourcepub fn binary(bytes: impl IntoIterator<Item = u8>) -> Self
pub fn binary(bytes: impl IntoIterator<Item = u8>) -> Self
Creates a binary value from bytes.
§Examples
use paramdef::core::Value;
let value = Value::binary([0x00, 0x01, 0x02]);
assert_eq!(value.as_binary().map(|b| b.len()), Some(3));