Skip to main content

sim_value/
lib.rs

1//! Ergonomic construction and access for kernel `Expr` data.
2//!
3//! The kernel `Expr` enum is bare data with no ergonomic surface, so dozens of
4//! libs independently re-grew `sym`/`number`/`field`/`set`/`expr_kind` and a
5//! `k`/`i` path-addressing scheme. This crate is the one home for that. It
6//! depends only on `sim-kernel` and adds data ergonomics, not runtime behavior,
7//! so it does not touch the kernel boundary.
8//!
9//! - [`build`]: constructors (`sym`, `int`, `float`, `text`, `list`, `map`, ...);
10//! - [`capability_names_from_expr`]: parses capability-name expressions;
11//! - [`access`]: reading and immutable updates (`field`, `set`, `remove`, ...);
12//! - [`kind`]: the one `Expr` variant classifier (`expr_kind`);
13//! - [`path`]: one value-addressing primitive (`Path`, `get`, `set_at`).
14//!
15//! # Example
16//!
17//! ```
18//! use sim_value::access::{field, set};
19//! use sim_value::build::{int, map, sym};
20//!
21//! let value = map(vec![("a", int(1)), ("b", int(2))]);
22//! assert_eq!(field(&value, "a"), Some(&int(1)));
23//!
24//! let updated = set(&value, "a", int(9));
25//! assert_eq!(field(&updated, "a"), Some(&int(9)));
26//! assert_eq!(field(&updated, "b"), Some(&int(2))); // siblings preserved
27//! let _ = sym("ok");
28//! ```
29
30#![forbid(unsafe_code)]
31#![deny(missing_docs)]
32
33pub mod access;
34pub mod build;
35pub mod capability;
36pub mod kind;
37pub mod path;
38
39pub use capability::capability_names_from_expr;
40
41#[cfg(test)]
42mod tests;