spacetimedb_sats/
array_type.rs

1use crate::algebraic_type::AlgebraicType;
2use crate::de::Deserialize;
3use crate::meta_type::MetaType;
4use crate::{impl_deserialize, impl_serialize, impl_st};
5
6/// An array type is a homogeneous product type of dynamic length.
7///
8/// That is, it is a product type
9/// where every element / factor / field is of the same type
10/// and where the length is statically unknown.
11#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
12pub struct ArrayType {
13    /// The base type every element of the array has.
14    pub elem_ty: Box<AlgebraicType>,
15}
16
17impl_serialize!([] ArrayType, (self, ser) => self.elem_ty.serialize(ser));
18impl_deserialize!([] ArrayType, de => Deserialize::deserialize(de).map(|elem_ty| Self { elem_ty }));
19impl_st!([] ArrayType, ts => AlgebraicType::make_type(ts));
20
21impl MetaType for ArrayType {
22    fn meta_type() -> AlgebraicType {
23        AlgebraicType::ZERO_REF
24    }
25}