SpacetimeType

Trait SpacetimeType 

Source
pub trait SpacetimeType {
    // Required method
    fn make_type<S>(typespace: &mut S) -> AlgebraicType
       where S: TypespaceBuilder;
}
Expand description

This trait makes types self-describing, allowing them to automatically register their structure with SpacetimeDB. This is used to tell SpacetimeDB about the structure of a module’s tables and reducers.

Deriving this trait also derives Serialize, Deserialize, and Debug. (There are currently no trait bounds on SpacetimeType documenting this fact.) Serialize and Deserialize are used to convert Rust data structures to other formats, suitable for storing on disk or passing over the network. Debug is simply for debugging convenience.

Any Rust type implementing SpacetimeType can be used as a table column or reducer argument. A derive macro is provided, and can be used on both structs and enums:


#[derive(SpacetimeType)]
struct Location {
    x: u64,
    y: u64
}

#[derive(SpacetimeType)]
struct PlasticCrate {
    count: u32,
}

#[derive(SpacetimeType)]
struct AppleCrate {
    variety: String,
    count: u32,
    freshness: u32,
}

#[derive(SpacetimeType)]
enum FruitCrate {
    Apples(AppleCrate),
    Plastic(PlasticCrate),
}

The fields of the struct/enum must also implement SpacetimeType.

Any type annotated with #[table(..)] automatically derives SpacetimeType.

SpacetimeType is implemented for many of the primitive types in the standard library:

  • bool
  • u8, u16, u32, u64, u128
  • i8, i16, i32, i64, i128
  • f32, f64

And common data structures:

  • String and &str, utf-8 string data
  • (), the unit type
  • Option<T> where T: SpacetimeType
  • Vec<T> where T: SpacetimeType

(Storing collections in rows of a database table is a form of denormalization.)

Do not manually implement this trait unless you are VERY sure you know what you’re doing. Implementations must be consistent with Deerialize<'de> for T, Serialize for T and Serialize, Deserialize for AlgebraicValue. Implementations that are inconsistent across these traits may result in data loss.

N.B.: It’s SpacetimeType, not SpaceTimeType.

Required Methods§

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.

The resulting AlgebraicType may contain Refs that only make sense within the context of this particular typespace.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl SpacetimeType for bool

Source§

impl SpacetimeType for f32

Source§

impl SpacetimeType for f64

Source§

impl SpacetimeType for i8

Source§

impl SpacetimeType for i16

Source§

impl SpacetimeType for i32

Source§

impl SpacetimeType for i64

Source§

impl SpacetimeType for i128

Source§

impl SpacetimeType for str

Source§

impl SpacetimeType for u8

Source§

impl SpacetimeType for u16

Source§

impl SpacetimeType for u32

Source§

impl SpacetimeType for u64

Source§

impl SpacetimeType for u128

Source§

impl SpacetimeType for ()

Source§

impl SpacetimeType for String

Source§

impl SpacetimeType for Bytes

Source§

impl SpacetimeType for I256

Source§

impl SpacetimeType for U256

Source§

impl SpacetimeType for Constraints

Source§

impl SpacetimeType for ColSet

Source§

impl SpacetimeType for ArgId

Source§

impl SpacetimeType for ColId

Source§

impl SpacetimeType for ConstraintId

Source§

impl SpacetimeType for IndexId

Source§

impl SpacetimeType for ScheduleId

Source§

impl SpacetimeType for SequenceId

Source§

impl SpacetimeType for TableId

Source§

impl SpacetimeType for ViewId

Source§

impl SpacetimeType for ColList

Source§

impl<T> SpacetimeType for Option<T>
where T: SpacetimeType,

Source§

impl<T> SpacetimeType for &T
where T: SpacetimeType + ?Sized,

Source§

impl<T> SpacetimeType for [T]
where T: SpacetimeType,

Source§

impl<T> SpacetimeType for Box<T>
where T: SpacetimeType + ?Sized,

Source§

impl<T> SpacetimeType for Rc<T>
where T: SpacetimeType + ?Sized,

Source§

impl<T> SpacetimeType for Arc<T>
where T: SpacetimeType + ?Sized,

Source§

impl<T> SpacetimeType for Vec<T>
where T: SpacetimeType,

Source§

impl<T, const N: usize> SpacetimeType for SmallVec<[T; N]>
where T: SpacetimeType,

Implementors§

Source§

impl SpacetimeType for StAccess

Source§

impl SpacetimeType for StTableType

Source§

impl SpacetimeType for IndexType

Source§

impl SpacetimeType for Lifecycle

Source§

impl SpacetimeType for RawConstraintDataV9

Source§

impl SpacetimeType for RawIndexAlgorithm

Source§

impl SpacetimeType for RawMiscModuleExportV9

Source§

impl SpacetimeType for TableAccess

Source§

impl SpacetimeType for TableType

Source§

impl SpacetimeType for AlgebraicType

Source§

impl SpacetimeType for MiscModuleExport

Source§

impl SpacetimeType for RawModuleDef

Source§

impl SpacetimeType for Method

Source§

impl SpacetimeType for Version

Source§

impl SpacetimeType for ScheduleAt

Source§

impl SpacetimeType for StVarValue

Source§

impl SpacetimeType for ConnectionId

Source§

impl SpacetimeType for ConnectionIdForUrl

Source§

impl SpacetimeType for ColumnAttribute

Source§

impl SpacetimeType for RawColumnDefV8

Source§

impl SpacetimeType for RawConstraintDefV8

Source§

impl SpacetimeType for RawIndexDefV8

Source§

impl SpacetimeType for RawSequenceDefV8

Source§

impl SpacetimeType for RawTableDefV8

Source§

impl SpacetimeType for RawColumnDefaultValueV9

Source§

impl SpacetimeType for RawConstraintDefV9

Source§

impl SpacetimeType for RawIndexDefV9

Source§

impl SpacetimeType for RawModuleDefV9

Source§

impl SpacetimeType for RawProcedureDefV9

Source§

impl SpacetimeType for RawReducerDefV9

Source§

impl SpacetimeType for RawRowLevelSecurityDefV9

Source§

impl SpacetimeType for RawScheduleDefV9

Source§

impl SpacetimeType for RawScopedTypeNameV9

Source§

impl SpacetimeType for RawSequenceDefV9

Source§

impl SpacetimeType for RawTableDefV9

Source§

impl SpacetimeType for RawTypeDefV9

Source§

impl SpacetimeType for RawUniqueConstraintDataV9

Source§

impl SpacetimeType for RawViewDefV9

Source§

impl SpacetimeType for Headers

Source§

impl SpacetimeType for Request

Source§

impl SpacetimeType for Response

Source§

impl SpacetimeType for AlgebraicTypeRef

Source§

impl SpacetimeType for ArrayType

Source§

impl SpacetimeType for SumTypeVariant

Source§

impl SpacetimeType for Typespace

Source§

impl SpacetimeType for Identity

Source§

impl SpacetimeType for Hash

Source§

impl SpacetimeType for ProductType

Source§

impl SpacetimeType for ProductTypeElement

Source§

impl SpacetimeType for RawModuleDefV8

Source§

impl SpacetimeType for ReducerDef

Source§

impl SpacetimeType for SumType

Source§

impl SpacetimeType for TableDesc

Source§

impl SpacetimeType for TimeDuration

Source§

impl SpacetimeType for Timestamp

Source§

impl SpacetimeType for TypeAlias