clockworklabs / clockworklabs/SpacetimeDB

Full Algebraic Type Support

Open
#5,301 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

This is somewhat related to #4031, but I would like full type support for enums, mainly named field variants

enum Birthday {
    Custom(String),
    // ? currently unsupported
    Date {
        day: u8,
        month: u8,
        year: Option<u16>
    }
}

as well as tuple variants

enum Birthday {
    Date(u8, u8, Option<u16>),
    ...
}

both currently error with must be a unit variant or a newtype variant

You can get around this by creating a struct and wrapping it as a newtype variant, but for types that will only ever be used as a single enum variant, that's not ideal.

In my testing manually implementing the derive macro, sats seems to support named field variants just fine, and with only that change you can deploy to maincloud without issue, reads and writes all work, only the module codegen step currently fails.

I haven't tested tuple variants, as I don't personally need them, they're just listed here to complete the type support.

Requested by @tyrantlink via the SpacetimeDB site.

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 at the derive macro and module codegen paths, comparing the existing unit and newtype variant handling with the named-field example in the issue. Verify named-field and tuple variants through reads and writes, then confirm the module codegen step succeeds without the “must be a unit variant or a newtype variant” error.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.