melodium_common/executive/
data_traits.rs

1use super::Value;
2use core::{fmt::Formatter, hash::Hasher};
3use erased_serde::{serialize_trait_object, Serialize, Serializer};
4
5pub trait DataTrait: Serialize {
6    fn to_i8(&self) -> i8;
7    fn to_i16(&self) -> i16;
8    fn to_i32(&self) -> i32;
9    fn to_i64(&self) -> i64;
10    fn to_i128(&self) -> i128;
11    fn to_u8(&self) -> u8;
12    fn to_u16(&self) -> u16;
13    fn to_u32(&self) -> u32;
14    fn to_u64(&self) -> u64;
15    fn to_u128(&self) -> u128;
16    fn to_f32(&self) -> f32;
17    fn to_f64(&self) -> f64;
18    fn to_bool(&self) -> bool;
19    fn to_byte(&self) -> u8;
20    fn to_char(&self) -> char;
21    fn to_string(&self) -> String;
22
23    fn try_to_i8(&self) -> Option<i8>;
24    fn try_to_i16(&self) -> Option<i16>;
25    fn try_to_i32(&self) -> Option<i32>;
26    fn try_to_i64(&self) -> Option<i64>;
27    fn try_to_i128(&self) -> Option<i128>;
28    fn try_to_u8(&self) -> Option<u8>;
29    fn try_to_u16(&self) -> Option<u16>;
30    fn try_to_u32(&self) -> Option<u32>;
31    fn try_to_u64(&self) -> Option<u64>;
32    fn try_to_u128(&self) -> Option<u128>;
33    fn try_to_f32(&self) -> Option<f32>;
34    fn try_to_f64(&self) -> Option<f64>;
35    fn try_to_bool(&self) -> Option<bool>;
36    fn try_to_byte(&self) -> Option<u8>;
37    fn try_to_char(&self) -> Option<char>;
38    fn try_to_string(&self) -> Option<String>;
39
40    fn saturating_to_i8(&self) -> i8;
41    fn saturating_to_i16(&self) -> i16;
42    fn saturating_to_i32(&self) -> i32;
43    fn saturating_to_i64(&self) -> i64;
44    fn saturating_to_i128(&self) -> i128;
45    fn saturating_to_u8(&self) -> u8;
46    fn saturating_to_u16(&self) -> u16;
47    fn saturating_to_u32(&self) -> u32;
48    fn saturating_to_u64(&self) -> u64;
49    fn saturating_to_u128(&self) -> u128;
50    fn saturating_to_f32(&self) -> f32;
51    fn saturating_to_f64(&self) -> f64;
52
53    // binary
54    fn binary_and(&self, other: &Value) -> Value;
55    fn binary_or(&self, other: &Value) -> Value;
56    fn binary_xor(&self, other: &Value) -> Value;
57    fn binary_not(&self) -> Value;
58
59    // signed
60    fn signed_abs(&self) -> Option<Value>;
61    fn signed_signum(&self) -> Value;
62    fn signed_is_positive(&self) -> bool;
63    fn signed_is_negative(&self) -> bool;
64
65    // float
66    fn float_is_nan(&self) -> bool;
67    fn float_is_infinite(&self) -> bool;
68    fn float_is_finite(&self) -> bool;
69    fn float_is_normal(&self) -> bool;
70    fn float_is_subnormal(&self) -> bool;
71    fn float_floor(&self) -> Value;
72    fn float_ceil(&self) -> Value;
73    fn float_round(&self) -> Value;
74    fn float_trunc(&self) -> Value;
75    fn float_fract(&self) -> Value;
76    fn float_recip(&self) -> Value;
77    fn float_pow(&self, n: &Value) -> Value;
78    fn float_sqrt(&self) -> Value;
79    fn float_exp(&self) -> Value;
80    fn float_exp2(&self) -> Value;
81    fn float_ln(&self) -> Value;
82    fn float_log(&self, base: &Value) -> Value;
83    fn float_log2(&self) -> Value;
84    fn float_log10(&self) -> Value;
85    fn float_cbrt(&self) -> Value;
86    fn float_hypot(&self, n: &Value) -> Value;
87    fn float_sin(&self) -> Value;
88    fn float_cos(&self) -> Value;
89    fn float_tan(&self) -> Value;
90    fn float_asin(&self) -> Value;
91    fn float_acos(&self) -> Value;
92    fn float_atan(&self) -> Value;
93    fn float_atan2(&self, n: &Value) -> Value;
94    fn float_sinh(&self) -> Value;
95    fn float_cosh(&self) -> Value;
96    fn float_tanh(&self) -> Value;
97    fn float_asinh(&self) -> Value;
98    fn float_acosh(&self) -> Value;
99    fn float_atanh(&self) -> Value;
100    fn float_to_degrees(&self) -> Value;
101    fn float_to_radians(&self) -> Value;
102
103    fn partial_equality_eq(&self, other: &Value) -> bool;
104    fn partial_equality_ne(&self, other: &Value) -> bool;
105
106    fn partial_order_lt(&self, other: &Value) -> bool;
107    fn partial_order_le(&self, other: &Value) -> bool;
108    fn partial_order_gt(&self, other: &Value) -> bool;
109    fn partial_order_ge(&self, other: &Value) -> bool;
110
111    fn order_max(&self, other: &Value) -> Value;
112    fn order_min(&self, other: &Value) -> Value;
113    fn order_clamp(&self, min: &Value, max: &Value) -> Value;
114
115    // Ops traits, one per line
116    fn add(&self, other: &Value) -> Value;
117    fn checked_add(&self, other: &Value) -> Option<Value>;
118    fn saturating_add(&self, other: &Value) -> Value;
119    fn wrapping_add(&self, other: &Value) -> Value;
120    fn sub(&self, other: &Value) -> Value;
121    fn checked_sub(&self, other: &Value) -> Option<Value>;
122    fn saturating_sub(&self, other: &Value) -> Value;
123    fn wrapping_sub(&self, other: &Value) -> Value;
124    fn mul(&self, other: &Value) -> Value;
125    fn checked_mul(&self, other: &Value) -> Option<Value>;
126    fn saturating_mul(&self, other: &Value) -> Value;
127    fn wrapping_mul(&self, other: &Value) -> Value;
128    fn div(&self, other: &Value) -> Value;
129    fn checked_div(&self, other: &Value) -> Option<Value>;
130    fn rem(&self, other: &Value) -> Value;
131    fn checked_rem(&self, other: &Value) -> Option<Value>;
132    fn neg(&self) -> Value;
133    fn checked_neg(&self) -> Option<Value>;
134    fn wrapping_neg(&self) -> Value;
135    fn pow(&self, exp: &u32) -> Value;
136    fn checked_pow(&self, exp: &u32) -> Option<Value>;
137
138    // euclid
139    fn euclid_div(&self, other: &Value) -> Value;
140    fn euclid_rem(&self, other: &Value) -> Value;
141    fn checked_euclid_div(&self, other: &Value) -> Option<Value>;
142    fn checked_euclid_rem(&self, other: &Value) -> Option<Value>;
143
144    fn hash(&self, state: &mut dyn Hasher);
145
146    fn serialize(&self, serializer: &mut dyn Serializer) -> Result<(), erased_serde::Error>;
147
148    fn display(&self, f: &mut Formatter<'_>) -> Result<(), core::fmt::Error>;
149}
150
151serialize_trait_object!(DataTrait);