AlgebraicType

Enum AlgebraicType 

Source
pub enum AlgebraicType {
Show 20 variants Ref(AlgebraicTypeRef), Sum(SumType), Product(ProductType), Array(ArrayType), String, Bool, I8, U8, I16, U16, I32, U32, I64, U64, I128, U128, I256, U256, F32, F64,
}
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, scalar value types, and convenience types strings, arrays, and maps, into a single type system.

Variants§

§

Ref(AlgebraicTypeRef)

A type where the definition is given by the typing context (Typespace). In other words, this is defined by a pointer to another AlgebraicType.

This should not be conflated with reference and pointer types in languages like Rust, In other words, this is not &T or *const T.

§

Sum(SumType)

A structural sum type.

Unlike most languages, sums in SATs are structural and not nominal. When checking whether two nominal types are the same, their names and/or declaration sites (e.g., module / namespace) are considered. Meanwhile, a structural type system would only check the structure of the type itself, e.g., the names of its variants and their inner data types in the case of a sum.

This is also known as a discriminated union (implementation) or disjoint union. Another name is coproduct (category theory).

These structures are known as sum types because the number of possible values a sum

{ N_0(T_0), N_1(T_1), ..., N_n(T_n) }

is:

Σ (i ∈ 0..n). values(T_i)

so for example, values({ A(U64), B(Bool) }) = values(U64) + values(Bool).

See also:

§

Product(ProductType)

A structural product type.

This is also known as struct and tuple in many languages, but note that unlike most languages, sums in SATs are structural and not nominal. When checking whether two nominal types are the same, their names and/or declaration sites (e.g., module / namespace) are considered. Meanwhile, a structural type system would only check the structure of the type itself, e.g., the names of its fields and their types in the case of a record. The name “product” comes from category theory.

See also:

These structures are known as product types because the number of possible values in product

{ N_0: T_0, N_1: T_1, ..., N_n: T_n }

is:

Π (i ∈ 0..n). values(T_i)

so for example, values({ A: U64, B: Bool }) = values(U64) * values(Bool).

§

Array(ArrayType)

The type of array values where elements are of a base type elem_ty. Values AlgebraicValue::Array(array) will have this type.

§

String

The UTF-8 encoded String type. Values AlgebraicValue::String(s) will have this type.

This type exists for convenience and because it is easy to just use Rust’s String (UTF-8) as opposed to rolling your own equivalent byte-array based UTF-8 encoding.

§

Bool

The bool type. Values AlgebraicValue::Bool(b) will have this type.

§

I8

The I8 type. Values AlgebraicValue::I8(v) will have this type.

§

U8

The U8 type. Values AlgebraicValue::U8(v) will have this type.

§

I16

The I16 type. Values AlgebraicValue::I16(v) will have this type.

§

U16

The U16 type. Values AlgebraicValue::U16(v) will have this type.

§

I32

The I32 type. Values AlgebraicValue::I32(v) will have this type.

§

U32

The U32 type. Values AlgebraicValue::U32(v) will have this type.

§

I64

The I64 type. Values AlgebraicValue::I64(v) will have this type.

§

U64

The U64 type. Values AlgebraicValue::U64(v) will have this type.

§

I128

The I128 type. Values AlgebraicValue::I128(v) will have this type.

§

U128

The U128 type. Values AlgebraicValue::U128(v) will have this type.

§

I256

The I256 type. Values AlgebraicValue::I256(v) will have this type.

§

U256

The U256 type. Values AlgebraicValue::U256(v) will have this type.

§

F32

The F32 type. Values AlgebraicValue::F32(v) will have this type.

§

F64

The F64 type. Values AlgebraicValue::F64(v) will have this type.

Implementations§

Source§

impl AlgebraicType

Source

pub fn is_ref(&self) -> bool

Returns true if this is a AlgebraicType::Ref, otherwise false

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

pub fn is_sum(&self) -> bool

Returns true if this is a AlgebraicType::Sum, otherwise false

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 is_product(&self) -> bool

Returns true if this is a AlgebraicType::Product, otherwise false

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 is_array(&self) -> bool

Returns true if this is a AlgebraicType::Array, otherwise false

Source

pub fn as_array_mut(&mut self) -> Option<&mut ArrayType>

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

Source

pub fn as_array(&self) -> Option<&ArrayType>

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

Source

pub fn into_array(self) -> Result<ArrayType, AlgebraicType>

Returns the inner fields if this is a AlgebraicType::Array, otherwise returns back the enum in the Err case of the result

Source

pub fn is_string(&self) -> bool

Returns true if this is a AlgebraicType::String, otherwise false

Source

pub fn is_bool(&self) -> bool

Returns true if this is a AlgebraicType::Bool, otherwise false

Source

pub fn is_i8(&self) -> bool

Returns true if this is a AlgebraicType::I8, otherwise false

Source

pub fn is_u8(&self) -> bool

Returns true if this is a AlgebraicType::U8, otherwise false

Source

pub fn is_i16(&self) -> bool

Returns true if this is a AlgebraicType::I16, otherwise false

Source

pub fn is_u16(&self) -> bool

Returns true if this is a AlgebraicType::U16, otherwise false

Source

pub fn is_i32(&self) -> bool

Returns true if this is a AlgebraicType::I32, otherwise false

Source

pub fn is_u32(&self) -> bool

Returns true if this is a AlgebraicType::U32, otherwise false

Source

pub fn is_i64(&self) -> bool

Returns true if this is a AlgebraicType::I64, otherwise false

Source

pub fn is_u64(&self) -> bool

Returns true if this is a AlgebraicType::U64, otherwise false

Source

pub fn is_i128(&self) -> bool

Returns true if this is a AlgebraicType::I128, otherwise false

Source

pub fn is_u128(&self) -> bool

Returns true if this is a AlgebraicType::U128, otherwise false

Source

pub fn is_i256(&self) -> bool

Returns true if this is a AlgebraicType::I256, otherwise false

Source

pub fn is_u256(&self) -> bool

Returns true if this is a AlgebraicType::U256, otherwise false

Source

pub fn is_f32(&self) -> bool

Returns true if this is a AlgebraicType::F32, otherwise false

Source

pub fn is_f64(&self) -> bool

Returns true if this is a AlgebraicType::F64, otherwise false

Source§

impl AlgebraicType

Source

pub const ZERO_REF: AlgebraicType

The first type in the typespace.

Source

pub fn is_connection_id(&self) -> bool

Returns whether this type is the ConnectionId type.

Construct an instance of this type with Self::connection_id

Source

pub fn is_identity(&self) -> bool

Returns whether this type is the conventional identity type.

Source

pub fn is_timestamp(&self) -> bool

Returns whether this type is the conventional point-in-time Timestamp type.

Source

pub fn is_time_duration(&self) -> bool

Returns whether this type is the conventional time-delta TimeDuration type.

Source

pub fn is_schedule_at(&self) -> bool

Returns whether this type is the conventional ScheduleAt type.

Source

pub fn is_unit(&self) -> bool

Returns whether this type is a unit type.

Source

pub fn is_never(&self) -> bool

Returns whether this type is a never type.

Source

pub fn as_option(&self) -> Option<&AlgebraicType>

If this type is the standard option type, returns the type of the some variant. Otherwise, returns None.

Source

pub fn is_scalar_or_string(&self) -> bool

Returns whether this type is scalar or a string type.

Source

pub fn is_scalar(&self) -> bool

Returns whether this type is one which holds a scalar value.

A scalar value is one not made up of other values, i.e., not composite. These are all integer and float values, i.e., integer and float types are scalar. References to other types, i.e., AlgebraicType::Refs are not scalar.

Source

pub fn is_signed(&self) -> bool

Returns whether the type is a signed integer type.

Source

pub fn is_unsigned(&self) -> bool

Returns whether the type is an unsigned integer type.

Source

pub fn is_integer(&self) -> bool

Returns whether this type is one of the integer types, e.g., U64 and I32.

Source

pub fn is_float(&self) -> bool

Returns whether the type is a float type.

Source

pub fn unit() -> AlgebraicType

The canonical 0-element unit type.

Source

pub fn never() -> AlgebraicType

The canonical 0-variant “never” / “absurd” / “void” type.

Source

pub fn bytes() -> AlgebraicType

A type representing an array of U8s.

Source

pub fn is_bytes(&self) -> bool

Returns whether this type is AlgebraicType::bytes().

Source

pub fn contains_refs(&self) -> bool

Whether this type, or the types it references, contain any AlgebraicTypeRefs.

Source

pub fn sum<S>(sum: S) -> AlgebraicType
where S: Into<SumType>,

Returns a sum type with the given sum.

Source

pub fn product<P>(prod: P) -> AlgebraicType
where P: Into<ProductType>,

Returns a product type with the given prod.

Source

pub fn option(some_type: AlgebraicType) -> AlgebraicType

Returns a structural option type where some_type is the type for the some variant.

Source

pub fn array(ty: AlgebraicType) -> AlgebraicType

Returns an unsized array type where the element type is ty.

Source

pub fn identity() -> AlgebraicType

Construct a copy of the Identity type.

Source

pub fn connection_id() -> AlgebraicType

Construct a copy of the ConnectionId type.

Source

pub fn timestamp() -> AlgebraicType

Construct a copy of the point-in-time Timestamp type.

Source

pub fn time_duration() -> AlgebraicType

Construct a copy of the time-delta TimeDuration type.

Source

pub fn simple_enum<'a>( var_names: impl Iterator<Item = &'a str>, ) -> AlgebraicType

Returns a sum type of unit variants with names taken from var_names.

Source

pub fn as_value(&self) -> AlgebraicValue

Source

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

Source

pub fn min_value(&self) -> Option<AlgebraicValue>

Given an AlgebraicType, returns the min value for that type.

Source

pub fn max_value(&self) -> Option<AlgebraicValue>

Given an AlgebraicType, returns the max value for that type.

Source

pub fn is_special(&self) -> bool

Check if the type is one of a small number of special, known types with specific layouts. See also ProductType::is_special and SumType::is_special.

Source

pub fn is_valid_for_client_type_definition(&self) -> bool

Validates that the type can be used to generate a type definition in a SpacetimeDB client module.

Such a type must be a non-special sum or product type. All of the elements of the type must satisfy AlgebraicType::is_valid_for_client_type_use.

This method does not actually follow Refs to check the types they point to, it only checks the structure of this type.

Source

pub fn is_valid_for_client_type_use(&self) -> bool

Validates that the type can be used to generate a use of a type in a SpacetimeDB client module. (As opposed to a definition of a type.)

This means that the type is either:

This method does not actually follow Refs to check the types they point to, it only checks the structure of the type.

Source

pub fn type_check(&self, value: &AlgebraicValue, typespace: &Typespace) -> bool

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 duplicate 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 Default for AlgebraicType

Provided to enable mem::take.

Source§

fn default() -> AlgebraicType

Returns the “default value” for a type. 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>,

Deserialize this value from the given deserializer.
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 From<AlgebraicType> for ProductType

Source§

fn from(x: AlgebraicType) -> ProductType

Converts to this type from the input type.
Source§

impl From<AlgebraicType> for ProductTypeElement

Source§

fn from(value: AlgebraicType) -> ProductTypeElement

Converts to this type from the input type.
Source§

impl From<AlgebraicTypeRef> for AlgebraicType

Source§

fn from(original: AlgebraicTypeRef) -> AlgebraicType

Converts to this type from the input type.
Source§

impl From<ArrayType> for AlgebraicType

Source§

fn from(original: ArrayType) -> AlgebraicType

Converts to this type from the input type.
Source§

impl From<ProductType> for AlgebraicType

Source§

fn from(original: ProductType) -> AlgebraicType

Converts to this type from the input type.
Source§

impl From<SumType> for AlgebraicType

Source§

fn from(original: SumType) -> AlgebraicType

Converts to this type from the input type.
Source§

impl Hash for AlgebraicType

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl MetaType for AlgebraicType

Source§

fn 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§

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) -> Self
where Self: Sized,

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

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

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

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

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

impl PartialEq for AlgebraicType

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd 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

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

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

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

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 self in the data format of S using the provided serializer.
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 SpacetimeType for AlgebraicType

Source§

fn make_type<S>(__typespace: &mut S) -> AlgebraicType

Returns an AlgebraicType representing the type for Self in SATS and in the typing context in typespace. This is used by the automatic type registration system in Rust modules. Read more
Source§

impl Eq for AlgebraicType

Source§

impl StructuralPartialEq for AlgebraicType

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Satn for T
where T: Serialize + ?Sized,

Source§

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

Formats the value using the SATN data format into the formatter f.
Source§

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

Formats the value using the postgres SATN(PsqlFormatter { f }, /* PsqlType */) formatter f.
Source§

fn to_satn(&self) -> String

Formats the value using the SATN data format into the returned String.
Source§

fn to_satn_pretty(&self) -> String

Pretty prints the value using the SATN data format into the returned String.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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