spacetimedb_sats/
convert.rs1use crate::{i256, u256};
2use crate::{AlgebraicType, AlgebraicValue, ProductType, ProductValue};
3use spacetimedb_primitives::{ColId, ConstraintId, IndexId, ScheduleId, SequenceId, TableId};
4
5impl crate::Value for AlgebraicValue {
6 type Type = AlgebraicType;
7}
8
9impl<X: Into<Box<[AlgebraicValue]>>> From<X> for ProductValue {
10 fn from(elements: X) -> Self {
11 let elements = elements.into();
12 ProductValue { elements }
13 }
14}
15
16impl From<AlgebraicValue> for ProductValue {
17 fn from(x: AlgebraicValue) -> Self {
18 [x].into()
19 }
20}
21
22impl From<AlgebraicType> for ProductType {
23 fn from(x: AlgebraicType) -> Self {
24 Self::new([x.into()].into())
25 }
26}
27
28macro_rules! built_in_into {
29 ($native:ty, $kind:ident) => {
30 impl From<$native> for AlgebraicValue {
31 fn from(x: $native) -> Self {
32 Self::$kind(x.into())
33 }
34 }
35 };
36}
37
38built_in_into!(u128, U128);
39built_in_into!(i128, I128);
40built_in_into!(u256, U256);
41built_in_into!(i256, I256);
42built_in_into!(f32, F32);
43built_in_into!(f64, F64);
44built_in_into!(&str, String);
45built_in_into!(String, String);
46built_in_into!(&[u8], Bytes);
47built_in_into!(Box<[u8]>, Bytes);
48
49macro_rules! system_id {
50 ($name:ident) => {
51 impl From<$name> for AlgebraicValue {
52 fn from(value: $name) -> Self {
53 value.0.into()
54 }
55 }
56 };
57}
58system_id!(TableId);
59system_id!(ColId);
60system_id!(SequenceId);
61system_id!(IndexId);
62system_id!(ConstraintId);
63system_id!(ScheduleId);