Skip to main content

voxgig_struct/
lib.rs

1// Copyright (c) 2025-2026 Voxgig Ltd. MIT LICENSE.
2// VERSION: @voxgig/struct 0.1.0
3//
4// Voxgig Struct — Rust port of the canonical TypeScript implementation
5// (ts/src/StructUtility.ts). See rs/PLAN.md for the porting plan and the
6// list of deliberate divergences (idiomatic snake_case names, Rc<RefCell>
7// reference-stable nodes, merge as a direct recursion, ...).
8
9#![allow(clippy::too_many_arguments)]
10
11pub mod consts;
12pub mod ordered_map;
13pub mod re;
14pub mod value;
15
16mod major;
17mod mini;
18
19pub use value::{Sentinel, Value, DELETE, SKIP};
20
21pub use consts::{
22    M_KEYPOST, M_KEYPRE, M_VAL, T_ANY, T_BOOLEAN, T_DECIMAL, T_FUNCTION, T_INSTANCE, T_INTEGER,
23    T_LIST, T_MAP, T_NODE, T_NOVAL, T_NULL, T_NUMBER, T_SCALAR, T_STRING, T_SYMBOL,
24};
25
26pub use mini::{
27    clone, del_prop, esc_re, esc_url, filter, filter_vals, flatten, get_def, get_elem,
28    get_elem_or_else, get_prop, has_key, is_empty, is_func, is_key, is_list, is_map, is_node,
29    items, jm, join, join_vals, jsonify, jt, keys_of, keysof_vec, lookup, pad, pathify, re_compile,
30    re_escape, re_find, re_find_all, re_replace, re_test, set_prop, size, slice, str_key,
31    stringify, type_name, typify,
32};
33
34pub use major::{
35    check_placement, get_path, get_path_inj, inject, inject_child, injector_args, merge, select,
36    set_path, transform, validate, walk, Inj, InjectDef, Injection, Modify, NativeFn, WalkClosure,
37};
38
39pub use mini::JsonFlags;
40
41/// Error raised by `transform` / `validate` when no error collector was
42/// supplied (mirrors the TS `throw new Error(errs.join(' | '))`).
43#[derive(Debug, Clone)]
44pub struct StructError {
45    pub message: String,
46}
47
48impl std::fmt::Display for StructError {
49    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
50        f.write_str(&self.message)
51    }
52}
53
54impl std::error::Error for StructError {}
55
56/// Bundle of all functions, mirroring the TS `StructUtility` class. Useful
57/// for the test harness (which looks subjects up by name).
58pub struct StructUtility;
59
60impl StructUtility {
61    pub fn new() -> Self {
62        StructUtility
63    }
64}
65
66impl Default for StructUtility {
67    fn default() -> Self {
68        StructUtility
69    }
70}