pub enum Value {
Undefined,
Null,
Boolean(bool),
Number(f64),
Date(f64),
String(String),
Array(Array),
Function(Function),
Object(Object),
}Expand description
A JavaScript value.
Values can either hold direct values (undefined, null, booleans, numbers, dates) or references
(strings, arrays, functions, other objects). Cloning values (via Rust’s Clone) of the direct
types defers to Rust’s Copy, while cloning values of the referential types results in a simple
reference clone similar to JavaScript’s own “by-reference” semantics.
Variants§
Undefined
The JavaScript value undefined.
Null
The JavaScript value null.
Boolean(bool)
The JavaScript value true or false.
Number(f64)
A JavaScript floating point number.
Date(f64)
Elapsed milliseconds since Unix epoch.
String(String)
An immutable JavaScript string, managed by V8.
Array(Array)
Reference to a JavaScript arrray.
Function(Function)
Reference to a JavaScript function.
Object(Object)
Reference to a JavaScript object. If a value is a function or an array in JavaScript, it
will be converted to Value::Array or Value::Function instead of Value::Object.
Implementations§
Source§impl Value
impl Value
Sourcepub fn is_undefined(&self) -> bool
pub fn is_undefined(&self) -> bool
Returns true if this is a Value::Undefined, false otherwise.
Sourcepub fn is_boolean(&self) -> bool
pub fn is_boolean(&self) -> bool
Returns true if this is a Value::Boolean, false otherwise.
Sourcepub fn is_function(&self) -> bool
pub fn is_function(&self) -> bool
Returns true if this is a Value::Function, false otherwise.
Sourcepub fn as_undefined(&self) -> Option<()>
pub fn as_undefined(&self) -> Option<()>
Returns Some(()) if this is a Value::Undefined, None otherwise.
Sourcepub fn as_boolean(&self) -> Option<bool>
pub fn as_boolean(&self) -> Option<bool>
Returns Some if this is a Value::Boolean, None otherwise.
Sourcepub fn as_number(&self) -> Option<f64>
pub fn as_number(&self) -> Option<f64>
Returns Some if this is a Value::Number, None otherwise.
Sourcepub fn as_string(&self) -> Option<&String>
pub fn as_string(&self) -> Option<&String>
Returns Some if this is a Value::String, None otherwise.
Sourcepub fn as_array(&self) -> Option<&Array>
pub fn as_array(&self) -> Option<&Array>
Returns Some if this is a Value::Array, None otherwise.
Sourcepub fn as_function(&self) -> Option<&Function>
pub fn as_function(&self) -> Option<&Function>
Returns Some if this is a Value::Function, None otherwise.
Sourcepub fn as_object(&self) -> Option<&Object>
pub fn as_object(&self) -> Option<&Object>
Returns Some if this is a Value::Object, None otherwise.
Sourcepub fn into<T: FromValue>(self, mv8: &MiniV8) -> Result<T>
pub fn into<T: FromValue>(self, mv8: &MiniV8) -> Result<T>
A wrapper around FromValue::from_value.
Sourcepub fn coerce_boolean(&self, mv8: &MiniV8) -> bool
pub fn coerce_boolean(&self, mv8: &MiniV8) -> bool
Coerces a value to a boolean. Returns true if the value is “truthy”, false otherwise.
Sourcepub fn coerce_number(&self, mv8: &MiniV8) -> Result<f64>
pub fn coerce_number(&self, mv8: &MiniV8) -> Result<f64>
Coerces a value to a number. Nearly all JavaScript values are coercible to numbers, but this
may fail with a runtime error under extraordinary circumstances (e.g. if the ECMAScript
ToNumber implementation throws an error).
This will return std::f64::NAN if the value has no numerical equivalent.
Sourcepub fn coerce_string(&self, mv8: &MiniV8) -> Result<String>
pub fn coerce_string(&self, mv8: &MiniV8) -> Result<String>
Coerces a value to a string. Nearly all JavaScript values are coercible to strings, but this
may fail with a runtime error if toString() fails or under otherwise extraordinary
circumstances (e.g. if the ECMAScript ToString implementation throws an error).