pub enum Value {
Undefined,
Null,
Bool(bool),
Number(f64),
String(Arc<str>),
Array(Arc<Vec<Value>>),
Object(Arc<IndexMap<String, Value>>),
Date(DateTime<FixedOffset>),
Function(FnHandle),
}Expand description
A JavaScript-like value. Objects keep their insertion order.
Variants§
Undefined
Null
Bool(bool)
Number(f64)
String(Arc<str>)
Array(Arc<Vec<Value>>)
Object(Arc<IndexMap<String, Value>>)
Date(DateTime<FixedOffset>)
Function(FnHandle)
A function from JavaScript data, still in the runtime that made it.
Templates can call it; any other use of it is a trap (see
crate::functions).
Implementations§
Source§impl Value
impl Value
Sourcepub fn from_json(v: &Value) -> Value
pub fn from_json(v: &Value) -> Value
Converts JSON, keeping object key order (relies on serde_json’s preserve_order).
Sourcepub fn liquid_truthy(&self) -> bool
pub fn liquid_truthy(&self) -> bool
Liquid truthiness: only false, null and undefined are falsy.
Sourcepub fn js_truthy(&self) -> bool
pub fn js_truthy(&self) -> bool
JavaScript truthiness: false, 0, -0, NaN, "", null and undefined are falsy.
Sourcepub fn to_js_string(&self) -> String
pub fn to_js_string(&self) -> String
JavaScript’s String(v), printing a Date in UTC. Use
Value::to_js_string_in to print it in another zone.
Sourcepub fn to_js_string_in(&self, tz: Tz) -> String
pub fn to_js_string_in(&self, tz: Tz) -> String
JavaScript’s String(v), printing a Date as
Date.prototype.toString does in tz, with the zone’s long name:
Tue Mar 03 2026 19:00:00 GMT-0500 (Eastern Standard Time).
Sourcepub fn to_js_number(&self) -> f64
pub fn to_js_number(&self) -> f64
JavaScript’s Number(v). Arrays and objects go through their
string form, as ToPrimitive does; a Date is its time in
milliseconds.
Sourcepub fn js_entries(o: &IndexMap<String, Value>) -> Vec<(&String, &Value)>
pub fn js_entries(o: &IndexMap<String, Value>) -> Vec<(&String, &Value)>
An object’s entries in JavaScript’s own-key order: keys that are
array indexes ("0" to "4294967294", written canonically) come
first in numeric order, then the other keys in insertion order. This
is the order Object.keys and for...in give.
Sourcepub fn js_entries_or_trap(
o: &IndexMap<String, Value>,
) -> Option<Vec<(&String, &Value)>>
pub fn js_entries_or_trap( o: &IndexMap<String, Value>, ) -> Option<Vec<(&String, &Value)>>
Value::js_entries, or None when listing o is a trap (see
crate::traps::entries): a walk that meets one can stop, since the
render will be refused.