arithmetic_eval/env/
variable_map.rs1use core::{cmp::Ordering, fmt};
4
5use crate::{fns, Object, Value};
6
7#[derive(Debug, Clone, Copy, Default)]
18pub struct Prelude;
19
20impl Prelude {
21 pub fn iter<T>() -> impl Iterator<Item = (&'static str, Value<T>)>
23 where
24 T: 'static + Clone,
25 {
26 let array_object: Object<T> = Self::array_functions::<T>().collect();
27 [
28 ("false", Value::Bool(false)),
29 ("true", Value::Bool(true)),
30 ("defer", Value::native_fn(fns::Defer)),
31 ("if", Value::native_fn(fns::If)),
32 ("while", Value::native_fn(fns::While)),
33 ]
34 .into_iter()
35 .chain(Self::array_functions::<T>())
36 .chain([("Array", array_object.into())])
37 }
38
39 fn array_functions<T>() -> impl Iterator<Item = (&'static str, Value<T>)>
40 where
41 T: 'static + Clone,
42 {
43 [
44 ("all", Value::native_fn(fns::All)),
45 ("any", Value::native_fn(fns::Any)),
46 ("filter", Value::native_fn(fns::Filter)),
47 ("fold", Value::native_fn(fns::Fold)),
48 ("map", Value::native_fn(fns::Map)),
49 ("merge", Value::native_fn(fns::Merge)),
50 ("push", Value::native_fn(fns::Push)),
51 ]
52 .into_iter()
53 }
54}
55
56#[derive(Debug, Clone, Copy, Default)]
58pub struct Assertions;
59
60impl Assertions {
61 pub fn iter<T>() -> impl Iterator<Item = (&'static str, Value<T>)>
63 where
64 T: 'static + Clone + fmt::Display,
65 {
66 [
67 ("assert", Value::native_fn(fns::Assert)),
68 ("assert_eq", Value::native_fn(fns::AssertEq)),
69 (
70 "assert_fails",
71 Value::native_fn(fns::AssertFails::default()),
72 ),
73 ]
74 .into_iter()
75 }
76}
77
78#[derive(Debug, Clone, Copy, Default)]
80pub struct Comparisons;
81
82impl Comparisons {
83 pub fn iter<T>() -> impl Iterator<Item = (&'static str, Value<T>)> {
85 [
86 ("LESS", Value::opaque_ref(Ordering::Less)),
87 ("EQUAL", Value::opaque_ref(Ordering::Equal)),
88 ("GREATER", Value::opaque_ref(Ordering::Greater)),
89 ("cmp", Value::native_fn(fns::Compare::Raw)),
90 ("min", Value::native_fn(fns::Compare::Min)),
91 ("max", Value::native_fn(fns::Compare::Max)),
92 ]
93 .into_iter()
94 }
95}