#4031Requested

Add Rust NewType Support

Requested on GitHub by corrm
Energy Committed1,082,000TeVfrom 3 boosters

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`:
  1. I think best way to do it as a first step is to support the same currently supported(Column Types) types as underlying type.

    Your example from PR:

    #[derive(SpacetimeType)]
    pub struct Position(vecmath::Vector3<f64>);
    

    afaik if the underlying type are not derive Serialize, Deserialize no thing will work

  2. @CorrM That's just for usecase illustration purposes. No type will work that way without my patch, and at least some do with it.

  3. Hey @CorrM, yes as @egormanga pointed out, this is not currently supported.

  4. @bfops any update?

  5. Hi @CorrM, the full implementation of this feature is larger than a small PR.

    In the meantime, does a struct with a single named field work for you?

  6. Hi @CorrM, the full implementation of this feature is larger than a small PR.

    In the meantime, does a struct with a single named field work for you?

    if you mean something like that, Yes:

    #[derive(SpacetimeType)]
    struct SomeTable {
        value: u64
    }
    
  7. Centril added the feature-request label Feb 4, 2026
  8. Centril added the backward-compatible label Feb 4, 2026
  9. Centril added the enhancement label Feb 4, 2026
  10. @bfops state of this feature?

  11. Hey @corrm, this is unchanged. This hasn't been a high priority for us since there's a fairly trivial workaround.

    If it's a high priority for you, I recommend filing it via our feature requests page. Then other users will have an easier time finding and upvoting.

Boost this Request

Reopen this request?

The request will return to its prior live status.

Mark as Duplicate

Pick the request that Add Rust NewType Support is a duplicate of. Energy rolls up into that request and GitHub closes the linked issue as a duplicate with a timeline reference to the canonical.

Unmark Duplicate

Restore as an independent request. The linked GitHub issue will be reopened and its duplicate-of relationship cleared. The original timeline entries stay as history; the note below is posted as a follow-up comment.