pub enum Value {
Null,
Bool(bool),
Int(i64),
Float(f64),
Decimal(Decimal),
String(String),
Array(Vec<Value>),
Object(HashMap<String, Value>),
ObjectRef(ObjectHandle),
}Expand description
Language-agnostic value representation
This enum can represent any value that needs to be passed between the core library and language bindings. It maps to JSON types for easy serialization when communicating with the solver service.
§Example
use solverforge_core::Value;
let int_val = Value::from(42i64);
assert_eq!(int_val.as_int(), Some(42));
let str_val = Value::from("hello");
assert_eq!(str_val.as_str(), Some("hello"));Variants§
Null
Null/None value
Bool(bool)
Boolean value
Int(i64)
Integer value (64-bit)
Float(f64)
Floating point value
Decimal(Decimal)
Decimal value for precise arithmetic (scores, etc.)
String(String)
String value
Array(Vec<Value>)
Array/List of values
Object(HashMap<String, Value>)
Object/Map of string keys to values
ObjectRef(ObjectHandle)
Reference to a host language object
Implementations§
Source§impl Value
impl Value
Sourcepub fn as_float(&self) -> Option<f64>
pub fn as_float(&self) -> Option<f64>
Try to get this value as a float
This will also convert integers to floats.
Sourcepub fn as_decimal(&self) -> Option<Decimal>
pub fn as_decimal(&self) -> Option<Decimal>
Try to get this value as a decimal
Sourcepub fn as_array_mut(&mut self) -> Option<&mut Vec<Value>>
pub fn as_array_mut(&mut self) -> Option<&mut Vec<Value>>
Try to get this value as a mutable array
Sourcepub fn as_object(&self) -> Option<&HashMap<String, Value>>
pub fn as_object(&self) -> Option<&HashMap<String, Value>>
Try to get this value as an object/map
Sourcepub fn as_object_mut(&mut self) -> Option<&mut HashMap<String, Value>>
pub fn as_object_mut(&mut self) -> Option<&mut HashMap<String, Value>>
Try to get this value as a mutable object/map
Sourcepub fn as_object_ref(&self) -> Option<ObjectHandle>
pub fn as_object_ref(&self) -> Option<ObjectHandle>
Try to get this value as an object handle
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Value
impl<'de> Deserialize<'de> for Value
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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<ObjectHandle> for Value
impl From<ObjectHandle> for Value
Source§fn from(handle: ObjectHandle) -> Self
fn from(handle: ObjectHandle) -> Self
Converts to this type from the input type.
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 UnwindSafe for Value
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
🔬This is a nightly-only experimental API. (
clone_to_uninit)