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

source

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

source

pub fn as_sum(&self) -> Option<&SumType>

Optionally returns references to the inner fields if this is a AlgebraicType::Sum, otherwise None

source

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

source

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

source

pub fn as_product(&self) -> Option<&ProductType>

Optionally returns references to the inner fields if this is a AlgebraicType::Product, otherwise None

source

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

source

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

source

pub fn as_builtin(&self) -> Option<&BuiltinType>

Optionally returns references to the inner fields if this is a AlgebraicType::Builtin, otherwise None

source

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

source

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

source

pub fn as_ref(&self) -> Option<&AlgebraicTypeRef>

Optionally returns references to the inner fields if this is a AlgebraicType::Ref, otherwise None

source

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

source

pub const Bool: AlgebraicType = AlgebraicType::Builtin(BuiltinType::Bool)

source

pub const I8: AlgebraicType = AlgebraicType::Builtin(BuiltinType::I8)

source

pub const U8: AlgebraicType = AlgebraicType::Builtin(BuiltinType::U8)

source

pub const I16: AlgebraicType = AlgebraicType::Builtin(BuiltinType::I16)

source

pub const U16: AlgebraicType = AlgebraicType::Builtin(BuiltinType::U16)

source

pub const I32: AlgebraicType = AlgebraicType::Builtin(BuiltinType::I32)

source

pub const U32: AlgebraicType = AlgebraicType::Builtin(BuiltinType::U32)

source

pub const I64: AlgebraicType = AlgebraicType::Builtin(BuiltinType::I64)

source

pub const U64: AlgebraicType = AlgebraicType::Builtin(BuiltinType::U64)

source

pub const I128: AlgebraicType = AlgebraicType::Builtin(BuiltinType::I128)

source

pub const U128: AlgebraicType = AlgebraicType::Builtin(BuiltinType::U128)

source

pub const F32: AlgebraicType = AlgebraicType::Builtin(BuiltinType::F32)

source

pub const F64: AlgebraicType = AlgebraicType::Builtin(BuiltinType::F64)

source

pub const String: AlgebraicType = AlgebraicType::Builtin(BuiltinType::String)

source

pub fn bytes() -> AlgebraicType

source§

impl AlgebraicType

source

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.

source

pub fn make_never_type() -> AlgebraicType

source

pub const UNIT_TYPE: AlgebraicType = AlgebraicType::Product(ProductType{ elements: Vec::new(),})

source

pub fn make_option_type(some_type: AlgebraicType) -> AlgebraicType

source

pub fn as_value(&self) -> AlgebraicValue

source

pub fn from_value( value: &AlgebraicValue ) -> Result<AlgebraicType, ValueDeserializeError>

source§

impl AlgebraicType

source

pub fn decode<'a>( bytes: &mut impl BufReader<'a> ) -> Result<AlgebraicType, DecodeError>

source

pub fn encode(&self, bytes: &mut impl BufWriter)

Trait Implementations§

source§

impl Clone for AlgebraicType

source§

fn clone(&self) -> AlgebraicType

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for AlgebraicType

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for AlgebraicType

source§

fn deserialize<D>( deserializer: D ) -> Result<AlgebraicType, <D as Deserializer<'de>>::Error>where D: Deserializer<'de>,

source§

impl<'de> Deserialize<'de> for AlgebraicType

source§

fn deserialize<D>( deserializer: D ) -> Result<AlgebraicType, <D as Deserializer<'de>>::Error>where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Ord for AlgebraicType

source§

fn cmp(&self, other: &AlgebraicType) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl PartialEq<AlgebraicType> for AlgebraicType

source§

fn eq(&self, other: &AlgebraicType) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd<AlgebraicType> for AlgebraicType

source§

fn partial_cmp(&self, other: &AlgebraicType) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Serialize for AlgebraicType

source§

fn serialize<S>( &self, serializer: S ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Serialize for AlgebraicType

source§

fn serialize<S>( &self, __serializer: S ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where S: Serializer,

source§

impl Eq for AlgebraicType

source§

impl StructuralEq for AlgebraicType

source§

impl StructuralPartialEq for AlgebraicType

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,

source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,