clockworklabs / clockworklabs/SpacetimeDB

Using non-primitive rust types doesn’t work

Open
#2,379 1 comment 3 reactions 1 assignee View on GitHub

@coolreader18 is already working on this.

Since Mar 7, 2025.

Dominant language
Rust
Stars
25.2k
Forks
1.1k
Avg merge
2d 7h
Merged PRs (30d)
46

Description

If we try to use a type that isn’t a primitive rust type and it’s not a stdb table/tuple, the project won’t compile. Here is an example of using a uuid, which is defined in the uuid crate:

#[spacetimedb(table(1))]
pub struct MyStruct {
	my_uuid: uuid,
}

The reason this doesn’t compile, is that the macro generated functions for the table will want to be able to grab the schema for this type (because it knows its not a rust primitive)

error[E0425]: cannot find function `__struct_to_tuple__uuid` in this scope
  --> crates/bitcraft-mini/src/lib.rs:15:1
   |
15 | #[spacetimedb(table(1))]
   | ^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope
   |
   = note: this error originates in the attribute macro `spacetimedb` (in Nightly builds, run with -Z macro-backtrace for more info)

Best solution I could think of: treat this type as a json object. The TupleDef type for this field will just be string, and when we serialize/deserialize this type we just do it using json. As long as the type supports serde serialization we should be okay.

Alternate solution: We need a way for someone to add support for this type, likely by allowing them to specify a struct ⇒ TupleDef and TupleDef ⇒ struct func (plus any other required functions for that type).

Note: Because implement TupleTypeand similar hits error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate, then is useful to list with foreign types we could implement (like chrono, uuid, ...)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.