Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using non-primitive rust types doesn’t work #2379

Open
bfops opened this issue Mar 7, 2025 · 0 comments
Open

Using non-primitive rust types doesn’t work #2379

bfops opened this issue Mar 7, 2025 · 0 comments
Assignees

Comments

@bfops
Copy link
Collaborator

bfops commented Mar 7, 2025

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, ...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants