Skip to main content

flow_value/
lib.rs

1//! The Flow runtime value model.
2//!
3//! This crate is what a value *is* while a program runs, and the operations
4//! the language fixes on values rather than on any one program:
5//!
6//! - the built-in data types of `data.md` — unbounded [`Int`], exact
7//!   [`Decimal`], code-point [`Text`], [`Bytes`], [`List`], [`Dict`] and
8//!   [`Set`] sorted by key, [`Duration`] and [`Instant`] — with the operators
9//!   std declares for them, including where they fault ([`Fault`]);
10//! - records, enum values and tuples by declaration ([`Record`],
11//!   [`Variant`], [`Tuple`]);
12//! - `types.md`'s structural equality and total order over every data value
13//!   ([`compare`], [`equal`]), and the text form interpolation inserts
14//!   ([`interpolate`], [`text_form`]);
15//! - the values a run holds that are not data — functions and other
16//!   evaluator-made values ([`Native`]), task handles ([`TaskId`]) and host
17//!   tokens ([`HostToken`]) — which have none of those operations and are
18//!   refused by each of them ([`DataError`]).
19//!
20//! Every rule here is exact and independent of the host's word size, locale,
21//! hash order and floating-point unit: replay computes pure work again, so
22//! two implementations that disagreed on any result would disagree on a run.
23//!
24//! # What is deliberately absent
25//!
26//! **Types.** The checker owns types; at run time a value carries no type
27//! beyond the declaration a record or enum value needs for its text.
28//!
29//! **Encoding.** The JSON value encoding and its canonical form are
30//! `abi.md`'s and live with the protocol; this crate exposes the parts an
31//! encoder reads.
32//!
33//! **Limits.** An `Int` has no bound and a `Text` no size here; the host's
34//! limits on a program's own values are the evaluator's to enforce, and every
35//! measure it needs — [`Int::bits`], [`Text::byte_len`], [`Bytes::len`] —
36//! costs constant time.
37//!
38//! # Unicode
39//!
40//! Normalization, case mapping, grapheme segmentation and a `Regex`'s classes
41//! use the tables of one Unicode version, [`UNICODE_VERSION`], which std's
42//! version fixes. Every table comes from a pinned crate; none is the Rust
43//! toolchain's.
44//!
45//! # Depth
46//!
47//! Equality, order, text and dropping walk a value with a stack on the heap,
48//! never the native one, so a value nested as deeply as memory allows is
49//! compared, printed and dropped like any other.
50
51mod collection;
52mod decimal;
53mod error;
54mod int;
55mod render;
56mod shape;
57mod text;
58mod time;
59mod value;
60
61pub use collection::{Dict, List, Set};
62pub use decimal::{DIVISION_DIGITS, Decimal};
63pub use error::{DataError, Fault};
64pub use int::Int;
65pub use render::{interpolate, text_form, text_form_within};
66pub use shape::{Constructor, EnumShape, Payload, Record, RecordShape, Variant};
67pub use text::{Bytes, Text, UNICODE_VERSION};
68pub use time::{Duration, Instant};
69pub use value::{Holding, HostToken, Native, TaskId, Tuple, Value, compare, equal};
70
71pub use num_bigint::BigInt;
72
73#[cfg(test)]
74mod tests;