flow-lang-value 0.1.0-rc.5

The Flow runtime value model: data values, their equality, order and text, and the operations std's built-in types declare.
Documentation
//! The Flow runtime value model.
//!
//! This crate is what a value *is* while a program runs, and the operations
//! the language fixes on values rather than on any one program:
//!
//! - the built-in data types of `data.md` — unbounded [`Int`], exact
//!   [`Decimal`], code-point [`Text`], [`Bytes`], [`List`], [`Dict`] and
//!   [`Set`] sorted by key, [`Duration`] and [`Instant`] — with the operators
//!   std declares for them, including where they fault ([`Fault`]);
//! - records, enum values and tuples by declaration ([`Record`],
//!   [`Variant`], [`Tuple`]);
//! - `types.md`'s structural equality and total order over every data value
//!   ([`compare`], [`equal`]), and the text form interpolation inserts
//!   ([`interpolate`], [`text_form`]), written by the one walk every
//!   spelling of a value shares ([`Spelling`], [`spell_within`]);
//! - the values a run holds that are not data — functions and other
//!   evaluator-made values ([`Native`]), task handles ([`TaskId`]) and host
//!   tokens ([`HostToken`]) — which have none of those operations and are
//!   refused by each of them ([`DataError`]).
//!
//! Every rule here is exact and independent of the host's word size, locale,
//! hash order and floating-point unit: replay computes pure work again, so
//! two implementations that disagreed on any result would disagree on a run.
//!
//! # What is deliberately absent
//!
//! **Types.** The checker owns types; at run time a value carries no type
//! beyond the declaration a record or enum value needs for its text.
//!
//! **Encoding.** The value encoding and the history format are `abi.md`'s and
//! `trace.md`'s and live with the protocol and the history; this crate
//! exposes the parts an encoder reads and a decoder builds from.
//!
//! **Limits.** An `Int` has no bound and a `Text` no size here; the host's
//! limits on a program's own values are the evaluator's to enforce, and every
//! measure it needs — [`Int::bits`], [`Text::byte_len`], [`Bytes::len`] —
//! costs constant time.
//!
//! # Structure
//!
//! History writes a value once and points at it afterwards, and writes a
//! text, a list or a dictionary as a tree whose parts can be pointed at too
//! (`trace.md`, *Values*). The structure that takes is the structure a value
//! has here, so a writer reads it and a reader builds it again, sharing what
//! was shared:
//!
//! - [`Value::identity`] tells a value apart from those made separately, so
//!   a writer can point at a value it has written;
//! - [`List::parts`] and [`List::from_parts`] give a list as its front, a
//!   window onto a tree of shared [`Node`]s, and its back;
//!   [`Dict::root`] and [`Dict::from_tree`] a dictionary as its tree;
//!   [`Node::shape`], [`Node::leaf`] and [`Node::branch`] each node;
//! - [`Text::root`], [`Text::of_block`] and [`Text::join_shared`] a text as
//!   a tree of [`Node`]s whose leaves are [`Run`]s onto shared [`Block`]s.
//!
//! Every builder checks what it is given ([`StructureError`]) and keeps the
//! trees balanced, rebalancing a tree another writer did not keep balanced,
//! so a value read from history behaves as one made here.
//!
//! # Unicode
//!
//! Normalization, case mapping and grapheme segmentation use the tables of
//! one Unicode version, [`UNICODE_VERSION`], which std's version fixes. Every
//! table comes from a pinned crate; none is the Rust toolchain's.
//!
//! # Depth
//!
//! Equality, order, text and dropping walk a value with a stack on the heap,
//! never the native one, so a value nested as deeply as memory allows is
//! compared, printed and dropped like any other.

#![cfg_attr(all(coverage, test), feature(coverage_attribute))]

mod collection;
mod decimal;
mod error;
mod int;
mod render;
mod shape;
mod text;
mod time;
mod tree;
mod value;

pub use collection::{Dict, List, ListParts, Set};
pub use decimal::{DIVISION_DIGITS, Decimal};
pub use error::{DataError, Fault, StructureError};
pub use int::Int;
pub use render::{
    Part, Spelling, interpolate, interpolate_within, spell_within, text_form, text_form_within,
};
pub use shape::{Record, Variant};
pub use text::{Block, Bytes, Run, Text, UNICODE_VERSION};
pub use time::{Duration, Instant};
pub use tree::{Element, Keyed, Member, Node, Shape};
pub use value::{
    Carry, Difference, HostToken, Identity, Native, Parts, Path, Step, TaskId, Tuple, Value, Walk,
    compare, equal,
};

pub use num_bigint::BigInt;

#[cfg(test)]
#[cfg_attr(coverage, coverage(off))]
mod tests;