pub enum Value {
Unit,
Bool(bool),
Int(i64),
Float(u64),
Str(Arc<Text>),
List(Arc<Vec<Value>>),
Map(PMap<Value, Value>),
Data(Arc<Record>),
Html(Arc<Html>),
Attr(Arc<AttrValue>),
Closure(Arc<Closure>),
}Expand description
A runtime value.
Map and a record’s fields are both ordered on purpose and for the same reason Phase 0 chose
BTreeMap: iteration order is part of the rendered view, and replay must reproduce the patch
stream bit for bit, not merely the set of values.
Map is a PMap, not an Arc<BTreeMap>, because it is the fold’s accumulator: an update
must not copy it. See crate::pmap for why that structure and not another.
Variants§
Unit
Bool(bool)
Int(i64)
Float(u64)
A real, stored as an order-preserving key rather than as f64::to_bits, so that the
derived Ord is the numeric one.
A total order is not optional here — a map key and a component of the state digest need one
— and to_bits supplies one that disagrees with arithmetic: -1.0 has a larger bit pattern
than 1.0, so < answered backwards for every negative number and sort_by sorted the
negatives in reverse. Value::float applies the standard monotone transform instead
(flip the sign bit for a positive, invert every bit for a negative), which makes the two
orders the same order. docs/32 §32.2.
Str(Arc<Text>)
Text, with the two facts a character-indexed language needs about it: how many characters
there are, and whether a character index is a byte index. Text is why.
List(Arc<Vec<Value>>)
Map(PMap<Value, Value>)
Data(Arc<Record>)
A model instance or a union variant — see Record.
Behind one pointer rather than inline, and that is a size decision rather than a style one:
the three fields inline made every Value 48 bytes, so a list of a million integers
carried 32 bytes of nothing per element and a call frame paid for the widest variant it did
not hold. One Arc makes a Value 16.
Html(Arc<Html>)
Attr(Arc<AttrValue>)
An attribute waiting to be attached to an element.
Closure(Arc<Closure>)
Implementations§
Source§impl Value
impl Value
Sourcepub fn float(f: f64) -> Value
pub fn float(f: f64) -> Value
Make a real, canonicalising the two IEEE values that would otherwise break Eq.
-0.0 becomes 0.0 and every NaN becomes one NaN, because Value is Eq and Ord and
a fold’s accumulator is compared, hashed and used as a map key. IEEE 754 says NaN != NaN
and -0.0 == 0.0; both are irreconcilable with a total order, and the total order is the
one §3.7 needs. So Beck’s == on reals is structural, and docs/32 §32.2 says so where
somebody porting numeric code will read it.
pub fn as_f64(&self) -> Option<f64>
pub fn str_(s: impl AsRef<str>) -> Value
Sourcepub fn text(s: String) -> Value
pub fn text(s: String) -> Value
The same from a String that is already owned, which is most of the string primitives:
they build one and would otherwise copy it again on the way in.
pub fn as_str(&self) -> Option<&str>
pub fn as_int(&self) -> Option<i64>
pub fn as_bool(&self) -> Option<bool>
pub fn as_list(&self) -> Option<&Vec<Value>>
pub fn as_map(&self) -> Option<&PMap<Value, Value>>
pub fn as_html(&self) -> Option<&Html>
Sourcepub fn data(
ty: impl Into<Arc<str>>,
variant: Option<Arc<str>>,
fields: Fields,
) -> Value
pub fn data( ty: impl Into<Arc<str>>, variant: Option<Arc<str>>, fields: Fields, ) -> Value
Build a record or a union variant. The one constructor, so that the Arc and the map are
allocated in one place rather than at every call site.
Sourcepub fn record<const N: usize>(
ty: impl Into<Arc<str>>,
variant: Option<&str>,
fields: [(&str, Value); N],
) -> Value
pub fn record<const N: usize>( ty: impl Into<Arc<str>>, variant: Option<&str>, fields: [(&str, Value); N], ) -> Value
The same from a list of pairs, which is how most call sites have them.