Value

Enum Value 

Source
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

Source

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.

Source

pub fn as_f64(&self) -> Option<f64>

Source

pub fn str_(s: impl AsRef<str>) -> Value

Source

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.

Source

pub fn as_str(&self) -> Option<&str>

Source

pub fn as_int(&self) -> Option<i64>

Source

pub fn as_bool(&self) -> Option<bool>

Source

pub fn as_list(&self) -> Option<&Vec<Value>>

Source

pub fn as_map(&self) -> Option<&PMap<Value, Value>>

Source

pub fn as_html(&self) -> Option<&Html>

Source

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.

Source

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.

Source

pub fn field(&self, name: &str) -> Option<&Value>

Source

pub fn variant(&self) -> Option<&str>

Source

pub fn some(v: Value) -> Value

Source

pub fn none() -> Value

Source

pub fn ok(v: Value) -> Value

Source

pub fn err(v: Value) -> Value

Source

pub fn display(&self) -> String

How str(x) renders a value, and how a value becomes a Map key’s printed form.

Source

pub fn to_json(&self) -> Value

The wire form, used for command payloads carried by handlers and for the log.

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Value

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Value

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Value

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Ord for Value

Source§

fn cmp(&self, other: &Value) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Value

Source§

fn eq(&self, other: &Value) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Value

Source§

fn partial_cmp(&self, other: &Value) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Eq for Value

Source§

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§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.