clockworklabs / clockworklabs/SpacetimeDB

Add Rust NewType Support

Open
#4,031 9 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

backward-compatible enhancement feature-request
Dominant language
Rust
Stars
25.2k
Forks
1.1k
Avg merge
2d 7h
Merged PRs (30d)
46

Description

Is it supported already and im doing something wrong?

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, SpacetimeType)]
pub struct AccountId(pub u64);

#[table(name = account)]
pub struct Account {
    #[primary_key]
    #[auto_inc]
    pub id: AccountId,
    pub created_at: Timestamp,
}
1. proc-macro derive panicked
   message: called `Option::unwrap()` on a `None` value
2. proc-macro panicked: called `Option::unwrap()` on a `None` value

the trait bound `for<'de> schema::account::AccountId: spacetimedb::Deserialize<'de>` is not satisfied.
the column type `schema::account::AccountId` does not implement `SpacetimeType`
   table column types all must implement `SpacetimeType`
   if you own the type, try adding `#[derive(SpacetimeType)]` to its definition
   the following other types implement trait `spacetimedb::SpacetimeType`:

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.

Research direction

Start by reproducing the reported proc-macro and trait-bound errors with the AccountId and Account example from the issue. Trace the derive and table-column type handling to determine where the newtype is rejected; done means this example compiles and the resulting type supports the required serialization and SpacetimeType behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.