Enum spacetimedb_lib::type_def::TypeDef
source · pub enum TypeDef {
Sum(SumType),
Product(ProductType),
Builtin(BuiltinType),
Ref(AlgebraicTypeRef),
}Expand description
The SpacetimeDB Algebraic Type System (SATS) is a structural type system in which a nominal type system can be constructed.
The type system unifies the concepts sum types, product types, and built-in primitive types into a single type system.
Below are some common types you might implement in this type system.
type Unit = () // or (,) or , Product with zero elements
type Never = (|) // or | Sum with zero elements
type U8 = U8 // Builtin
type Foo = (foo: I8) != I8
type Bar = (bar: I8)
type Color = (a: I8 | b: I8) // Sum with one element
type Age = (age: U8) // Product with one element
type Option<T> = (some: T | none: ())
type Ref = &0
type AlgebraicType = (sum: SumType | product: ProductType | builtin: BuiltinType | set: AlgebraicType)
type Catalog<T> = (name: String, indices: Set<Set<Tag>>, relation: Set<>)
type CatalogEntry = { name: string, indexes: {some type}, relation: Relation }
type ElementValue = (tag: Tag, value: AlgebraicValue)
type AlgebraicValue = (sum: ElementValue | product: {ElementValue} | builtin: BuiltinValue | set: {AlgebraicValue})
type Any = (value: Bytes, type: AlgebraicType)
type Table<Row: ProductType> = (
rows: Array<Row>
)
type HashSet<T> = (
array: Array<T>
)
type BTreeSet<T> = (
array: Array<T>
)
type TableType<Row: ProductType> = (
relation: Table<Row>,
indexes: Array<(index_type: String)>,
)Variants§
Implementations§
source§impl AlgebraicType
impl AlgebraicType
sourcepub fn as_sum_mut(&mut self) -> Option<&mut SumType>
pub fn as_sum_mut(&mut self) -> Option<&mut SumType>
Optionally returns mutable references to the inner fields if this is a AlgebraicType::Sum, otherwise None
sourcepub fn as_sum(&self) -> Option<&SumType>
pub fn as_sum(&self) -> Option<&SumType>
Optionally returns references to the inner fields if this is a AlgebraicType::Sum, otherwise None
sourcepub fn into_sum(self) -> Result<SumType, AlgebraicType>
pub fn into_sum(self) -> Result<SumType, AlgebraicType>
Returns the inner fields if this is a AlgebraicType::Sum, otherwise returns back the enum in the Err case of the result
sourcepub fn as_product_mut(&mut self) -> Option<&mut ProductType>
pub fn as_product_mut(&mut self) -> Option<&mut ProductType>
Optionally returns mutable references to the inner fields if this is a AlgebraicType::Product, otherwise None
sourcepub fn as_product(&self) -> Option<&ProductType>
pub fn as_product(&self) -> Option<&ProductType>
Optionally returns references to the inner fields if this is a AlgebraicType::Product, otherwise None
sourcepub fn into_product(self) -> Result<ProductType, AlgebraicType>
pub fn into_product(self) -> Result<ProductType, AlgebraicType>
Returns the inner fields if this is a AlgebraicType::Product, otherwise returns back the enum in the Err case of the result
sourcepub fn as_builtin_mut(&mut self) -> Option<&mut BuiltinType>
pub fn as_builtin_mut(&mut self) -> Option<&mut BuiltinType>
Optionally returns mutable references to the inner fields if this is a AlgebraicType::Builtin, otherwise None
sourcepub fn as_builtin(&self) -> Option<&BuiltinType>
pub fn as_builtin(&self) -> Option<&BuiltinType>
Optionally returns references to the inner fields if this is a AlgebraicType::Builtin, otherwise None
sourcepub fn into_builtin(self) -> Result<BuiltinType, AlgebraicType>
pub fn into_builtin(self) -> Result<BuiltinType, AlgebraicType>
Returns the inner fields if this is a AlgebraicType::Builtin, otherwise returns back the enum in the Err case of the result
sourcepub fn as_ref_mut(&mut self) -> Option<&mut AlgebraicTypeRef>
pub fn as_ref_mut(&mut self) -> Option<&mut AlgebraicTypeRef>
Optionally returns mutable references to the inner fields if this is a AlgebraicType::Ref, otherwise None
sourcepub fn as_ref(&self) -> Option<&AlgebraicTypeRef>
pub fn as_ref(&self) -> Option<&AlgebraicTypeRef>
Optionally returns references to the inner fields if this is a AlgebraicType::Ref, otherwise None
sourcepub fn into_ref(self) -> Result<AlgebraicTypeRef, AlgebraicType>
pub fn into_ref(self) -> Result<AlgebraicTypeRef, AlgebraicType>
Returns the inner fields if this is a AlgebraicType::Ref, otherwise returns back the enum in the Err case of the result
source§impl AlgebraicType
impl AlgebraicType
pub const Bool: AlgebraicType = AlgebraicType::Builtin(BuiltinType::Bool)
pub const I8: AlgebraicType = AlgebraicType::Builtin(BuiltinType::I8)
pub const U8: AlgebraicType = AlgebraicType::Builtin(BuiltinType::U8)
pub const I16: AlgebraicType = AlgebraicType::Builtin(BuiltinType::I16)
pub const U16: AlgebraicType = AlgebraicType::Builtin(BuiltinType::U16)
pub const I32: AlgebraicType = AlgebraicType::Builtin(BuiltinType::I32)
pub const U32: AlgebraicType = AlgebraicType::Builtin(BuiltinType::U32)
pub const I64: AlgebraicType = AlgebraicType::Builtin(BuiltinType::I64)
pub const U64: AlgebraicType = AlgebraicType::Builtin(BuiltinType::U64)
pub const I128: AlgebraicType = AlgebraicType::Builtin(BuiltinType::I128)
pub const U128: AlgebraicType = AlgebraicType::Builtin(BuiltinType::U128)
pub const F32: AlgebraicType = AlgebraicType::Builtin(BuiltinType::F32)
pub const F64: AlgebraicType = AlgebraicType::Builtin(BuiltinType::F64)
pub const String: AlgebraicType = AlgebraicType::Builtin(BuiltinType::String)
pub fn bytes() -> AlgebraicType
source§impl AlgebraicType
impl AlgebraicType
sourcepub fn make_meta_type() -> AlgebraicType
pub fn make_meta_type() -> AlgebraicType
This is a static function that constructs the type of AlgebraicType and returns it as an AlgebraicType. This could alternatively be implemented as a regular AlgebraicValue or as a static variable.
pub fn make_never_type() -> AlgebraicType
pub const UNIT_TYPE: AlgebraicType = AlgebraicType::Product(ProductType{ elements: Vec::new(),})
pub fn make_option_type(some_type: AlgebraicType) -> AlgebraicType
pub fn as_value(&self) -> AlgebraicValue
pub fn from_value( value: &AlgebraicValue ) -> Result<AlgebraicType, ValueDeserializeError>
source§impl AlgebraicType
impl AlgebraicType
pub fn decode<'a>( bytes: &mut impl BufReader<'a> ) -> Result<AlgebraicType, DecodeError>
pub fn encode(&self, bytes: &mut impl BufWriter)
Trait Implementations§
source§impl Clone for AlgebraicType
impl Clone for AlgebraicType
source§fn clone(&self) -> AlgebraicType
fn clone(&self) -> AlgebraicType
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl Debug for AlgebraicType
impl Debug for AlgebraicType
source§impl<'de> Deserialize<'de> for AlgebraicType
impl<'de> Deserialize<'de> for AlgebraicType
fn deserialize<D>( deserializer: D ) -> Result<AlgebraicType, <D as Deserializer<'de>>::Error>where D: Deserializer<'de>,
source§impl<'de> Deserialize<'de> for AlgebraicType
impl<'de> Deserialize<'de> for AlgebraicType
source§fn deserialize<D>(
deserializer: D
) -> Result<AlgebraicType, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>( deserializer: D ) -> Result<AlgebraicType, <D as Deserializer<'de>>::Error>where D: Deserializer<'de>,
source§impl Ord for AlgebraicType
impl Ord for AlgebraicType
source§fn cmp(&self, other: &AlgebraicType) -> Ordering
fn cmp(&self, other: &AlgebraicType) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere Self: Sized,
source§impl PartialEq<AlgebraicType> for AlgebraicType
impl PartialEq<AlgebraicType> for AlgebraicType
source§fn eq(&self, other: &AlgebraicType) -> bool
fn eq(&self, other: &AlgebraicType) -> bool
self and other values to be equal, and is used
by ==.source§impl PartialOrd<AlgebraicType> for AlgebraicType
impl PartialOrd<AlgebraicType> for AlgebraicType
source§fn partial_cmp(&self, other: &AlgebraicType) -> Option<Ordering>
fn partial_cmp(&self, other: &AlgebraicType) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read more