Skip to content

enum

Value

pub enum Value {
    Null,
    Str(String),
    Num(f64),
    Bool(bool),
    List(Vec<Value>),
    Record(BTreeMap<String, Value>),
}

A runtime value. Templates are dynamically typed; Rust state is converted into Values at the scope boundary.

Variants

Null

Null

No value: null, a missing field, or nothing loaded yet.

Str

Str(String)

Text.

Num

Num(f64)

A number.

Bool

Bool(bool)

true or false.

List

List(Vec<Value>)

A list.

Record

Record(BTreeMap<String, Value>)

A record: fields by name, in name order.

Methods

record

pub fn record<K: Into<String>>(fields: impl IntoIterator<Item = (K, Value)>) -> Value

Build a record from (key, value) pairs.

to_text

pub fn to_text(&self) -> String

The text shown when the value is interpolated into a template.

truthy

pub fn truthy(&self) -> bool

Truthiness used by if blocks.

as_num

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

Numeric view (numeric strings are parsed).

as_str

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

The text, if it's text.

as_bool

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

The bool, if it's a bool.

as_map

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

The fields, if it's a record.

as_vec

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

The items, if it's a list.

field

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

A field of a record.

get_path

pub fn get_path(&self, segments: &[String]) -> Option<Value>

Follow a field path; lists expose a len pseudo-field.

Trait implementations