melodium_core/executive/
traits.rs1use crate::string;
2
3pub trait ToI8 {
4 fn to_i8(&self) -> i8;
5}
6
7pub trait ToI16 {
8 fn to_i16(&self) -> i16;
9}
10
11pub trait ToI32 {
12 fn to_i32(&self) -> i32;
13}
14
15pub trait ToI64 {
16 fn to_i64(&self) -> i64;
17}
18
19pub trait ToI128 {
20 fn to_i128(&self) -> i128;
21}
22
23pub trait ToU8 {
24 fn to_u8(&self) -> u8;
25}
26
27pub trait ToU16 {
28 fn to_u16(&self) -> u16;
29}
30
31pub trait ToU32 {
32 fn to_u32(&self) -> u32;
33}
34
35pub trait ToU64 {
36 fn to_u64(&self) -> u64;
37}
38
39pub trait ToU128 {
40 fn to_u128(&self) -> u128;
41}
42
43pub trait ToF32 {
44 fn to_f32(&self) -> f32;
45}
46
47pub trait ToF64 {
48 fn to_f64(&self) -> f64;
49}
50
51pub trait ToBool {
52 fn to_bool(&self) -> bool;
53}
54
55pub trait ToByte {
56 fn to_byte(&self) -> u8;
57}
58
59pub trait ToChar {
60 fn to_char(&self) -> char;
61}
62
63pub trait ToString {
64 fn to_string(&self) -> string;
65}
66
67pub trait TryToI8 {
68 fn try_to_i8(&self) -> Option<i8>;
69}
70
71pub trait TryToI16 {
72 fn try_to_i16(&self) -> Option<i16>;
73}
74
75pub trait TryToI32 {
76 fn try_to_i32(&self) -> Option<i32>;
77}
78
79pub trait TryToI64 {
80 fn try_to_i64(&self) -> Option<i64>;
81}
82
83pub trait TryToI128 {
84 fn try_to_i128(&self) -> Option<i128>;
85}
86
87pub trait TryToU8 {
88 fn try_to_u8(&self) -> Option<u8>;
89}
90
91pub trait TryToU16 {
92 fn try_to_u16(&self) -> Option<u16>;
93}
94
95pub trait TryToU32 {
96 fn try_to_u32(&self) -> Option<u32>;
97}
98
99pub trait TryToU64 {
100 fn try_to_u64(&self) -> Option<u64>;
101}
102
103pub trait TryToU128 {
104 fn try_to_u128(&self) -> Option<u128>;
105}
106
107pub trait TryToF32 {
108 fn try_to_f32(&self) -> Option<f32>;
109}
110
111pub trait TryToF64 {
112 fn try_to_f64(&self) -> Option<f64>;
113}
114
115pub trait TryToBool {
116 fn try_to_bool(&self) -> Option<bool>;
117}
118
119pub trait TryToByte {
120 fn try_to_byte(&self) -> Option<u8>;
121}
122
123pub trait TryToChar {
124 fn try_to_char(&self) -> Option<char>;
125}
126
127pub trait TryToString {
128 fn try_to_string(&self) -> Option<string>;
129}
130
131pub trait SaturatingToI8 {
132 fn saturating_to_i8(&self) -> i8;
133}
134
135pub trait SaturatingToI16 {
136 fn saturating_to_i16(&self) -> i16;
137}
138
139pub trait SaturatingToI32 {
140 fn saturating_to_i32(&self) -> i32;
141}
142
143pub trait SaturatingToI64 {
144 fn saturating_to_i64(&self) -> i64;
145}
146
147pub trait SaturatingToI128 {
148 fn saturating_to_i128(&self) -> i128;
149}
150
151pub trait SaturatingToU8 {
152 fn saturating_to_u8(&self) -> u8;
153}
154
155pub trait SaturatingToU16 {
156 fn saturating_to_u16(&self) -> u16;
157}
158
159pub trait SaturatingToU32 {
160 fn saturating_to_u32(&self) -> u32;
161}
162
163pub trait SaturatingToU64 {
164 fn saturating_to_u64(&self) -> u64;
165}
166
167pub trait SaturatingToU128 {
168 fn saturating_to_u128(&self) -> u128;
169}
170
171pub trait SaturatingToF32 {
172 fn saturating_to_f32(&self) -> f32;
173}
174
175pub trait SaturatingToF64 {
176 fn saturating_to_f64(&self) -> f64;
177}
178
179pub trait Binary {
180 fn and(&self, other: &Self) -> Self;
181 fn or(&self, other: &Self) -> Self;
182 fn xor(&self, other: &Self) -> Self;
183 fn not(&self) -> Self;
184}
185
186pub trait Signed: Sized {
187 fn abs(&self) -> Option<Self>;
188 fn signum(&self) -> Self;
189 fn is_positive(&self) -> bool;
190 fn is_negative(&self) -> bool;
191}
192
193pub trait Float {
194 fn is_nan(&self) -> bool;
195 fn is_infinite(&self) -> bool;
196 fn is_finite(&self) -> bool;
197 fn is_normal(&self) -> bool;
198 fn is_subnormal(&self) -> bool;
199 fn floor(&self) -> Self;
200 fn ceil(&self) -> Self;
201 fn round(&self) -> Self;
202 fn trunc(&self) -> Self;
203 fn fract(&self) -> Self;
204 fn recip(&self) -> Self;
205 fn pow(&self, n: &Self) -> Self;
206 fn sqrt(&self) -> Self;
207 fn exp(&self) -> Self;
208 fn exp2(&self) -> Self;
209 fn ln(&self) -> Self;
210 fn log(&self, base: &Self) -> Self;
211 fn log2(&self) -> Self;
212 fn log10(&self) -> Self;
213 fn cbrt(&self) -> Self;
214 fn hypot(&self, n: &Self) -> Self;
215 fn sin(&self) -> Self;
216 fn cos(&self) -> Self;
217 fn tan(&self) -> Self;
218 fn asin(&self) -> Self;
219 fn acos(&self) -> Self;
220 fn atan(&self) -> Self;
221 fn atan2(&self, n: &Self) -> Self;
222 fn sinh(&self) -> Self;
223 fn cosh(&self) -> Self;
224 fn tanh(&self) -> Self;
225 fn asinh(&self) -> Self;
226 fn acosh(&self) -> Self;
227 fn atanh(&self) -> Self;
228 fn to_degrees(&self) -> Self;
229 fn to_radians(&self) -> Self;
230}
231
232pub trait PartialEquality {
233 fn eq(&self, other: &Self) -> bool;
234 fn ne(&self, other: &Self) -> bool;
235}
236
237impl<T> PartialEquality for T
238where
239 T: core::cmp::PartialEq,
240{
241 fn eq(&self, other: &Self) -> bool {
242 core::cmp::PartialEq::eq(self, other)
243 }
244
245 fn ne(&self, other: &Self) -> bool {
246 core::cmp::PartialEq::ne(self, other)
247 }
248}
249
250pub trait PartialOrder {
251 fn lt(&self, other: &Self) -> bool;
252 fn le(&self, other: &Self) -> bool;
253 fn gt(&self, other: &Self) -> bool;
254 fn ge(&self, other: &Self) -> bool;
255}
256
257impl<T> PartialOrder for T
258where
259 T: core::cmp::PartialOrd,
260{
261 fn lt(&self, other: &Self) -> bool {
262 core::cmp::PartialOrd::lt(self, other)
263 }
264
265 fn le(&self, other: &Self) -> bool {
266 core::cmp::PartialOrd::le(self, other)
267 }
268
269 fn gt(&self, other: &Self) -> bool {
270 core::cmp::PartialOrd::gt(self, other)
271 }
272
273 fn ge(&self, other: &Self) -> bool {
274 core::cmp::PartialOrd::ge(self, other)
275 }
276}
277
278pub trait Order {
279 fn max(&self, other: &Self) -> Self;
280 fn min(&self, other: &Self) -> Self;
281 fn clamp(&self, min: &Self, max: &Self) -> Self;
282}
283
284impl<T> Order for T
285where
286 T: core::cmp::Ord + Clone,
287{
288 fn max(&self, other: &Self) -> Self {
289 core::cmp::Ord::max(self, other).clone()
290 }
291
292 fn min(&self, other: &Self) -> Self {
293 core::cmp::Ord::min(self, other).clone()
294 }
295
296 fn clamp(&self, min: &Self, max: &Self) -> Self {
297 core::cmp::Ord::clamp(self, min, max).clone()
298 }
299}
300
301pub trait Add {
302 fn add(&self, other: &Self) -> Self;
303}
304
305pub trait CheckedAdd: Sized {
306 fn checked_add(&self, other: &Self) -> Option<Self>;
307}
308
309pub trait SaturatingAdd {
310 fn saturating_add(&self, other: &Self) -> Self;
311}
312
313pub trait WrappingAdd {
314 fn wrapping_add(&self, other: &Self) -> Self;
315}
316
317pub trait Sub {
318 fn sub(&self, other: &Self) -> Self;
319}
320
321pub trait CheckedSub: Sized {
322 fn checked_sub(&self, other: &Self) -> Option<Self>;
323}
324
325pub trait SaturatingSub {
326 fn saturating_sub(&self, other: &Self) -> Self;
327}
328
329pub trait WrappingSub {
330 fn wrapping_sub(&self, other: &Self) -> Self;
331}
332
333pub trait Mul {
334 fn mul(&self, other: &Self) -> Self;
335}
336
337pub trait CheckedMul: Sized {
338 fn mul(&self, other: &Self) -> Option<Self>;
339}
340
341pub trait SaturatingMul {
342 fn saturating_mul(&self, other: &Self) -> Self;
343}
344
345pub trait WrappingMul {
346 fn wrapping_mul(&self, other: &Self) -> Self;
347}
348
349pub trait Div {
350 fn div(&self, other: &Self) -> Self;
351}
352
353pub trait CheckedDiv: Sized {
354 fn checked_div(&self, other: &Self) -> Option<Self>;
355}
356
357pub trait Rem {
358 fn rem(&self, other: &Self) -> Self;
359}
360
361pub trait CheckedRem: Sized {
362 fn checked_rem(&self, other: &Self) -> Option<Self>;
363}
364
365pub trait Neg {
366 fn neg(&self) -> Self;
367}
368
369pub trait CheckedNeg: Sized {
370 fn checked_neg(&self) -> Option<Self>;
371}
372
373pub trait WrappingNeg {
374 fn wrapping_neg(&self) -> Self;
375}
376
377pub trait Pow {
378 fn pow(&self, exp: &u32) -> Self;
379}
380
381pub trait CheckedPow: Sized {
382 fn checked_pow(&self, exp: &u32) -> Option<Self>;
383}
384
385pub trait Euclid {
386 fn euclid_div(&self, other: &Self) -> Self;
387 fn euclid_rem(&self, other: &Self) -> Self;
388}
389
390pub trait CheckedEuclid: Sized {
391 fn checked_euclid_div(&self, other: &Self) -> Option<Self>;
392 fn checked_euclid_rem(&self, other: &Self) -> Option<Self>;
393}
394
395pub trait Hash {
396 fn hash(&self, state: &mut dyn core::hash::Hasher);
397}
398
399impl<T> Hash for T
400where
401 T: core::hash::Hash,
402{
403 fn hash(&self, mut state: &mut dyn core::hash::Hasher) {
404 core::hash::Hash::hash(&self, &mut state)
405 }
406}
407
408pub trait Serialize {
409 fn serialize(
410 &self,
411 serializer: &mut dyn crate::ErasedSerializer,
412 ) -> Result<(), crate::ErasedSerdeError>;
413}
414
415impl<T> Serialize for T
416where
417 T: crate::ErasedSerialize,
418{
419 fn serialize(
420 &self,
421 serializer: &mut dyn crate::ErasedSerializer,
422 ) -> Result<(), crate::ErasedSerdeError> {
423 self.erased_serialize(serializer)
424 }
425}
426
427pub trait Display {
428 fn display(&self, f: &mut core::fmt::Formatter<'_>) -> Result<(), core::fmt::Error>;
429}
430
431impl<T> Display for T
432where
433 T: core::fmt::Display,
434{
435 fn display(&self, f: &mut core::fmt::Formatter<'_>) -> Result<(), core::fmt::Error> {
436 core::fmt::Display::fmt(self, f)
437 }
438}