clockworklabs / clockworklabs/SpacetimeDB
Option to codegen impl blocks
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 25.2k
- Forks
- 1.1k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 46
Description
I want to be able to define a SpacetimeType, impl From<> for a shared type, then have that impl optionally added to the codegen for use on client. The best example I can think of for this is Vec3 and Vec2 shapes, so maybe something like this:
Define your type and the impl blocks, then add #[spacetime_export] to them. This is also helpful if you want to write common functionality in the impl block and share between server + client instead of writing a separate common crate.
#[derive(SpacetimeType)]
pub struct Vec3 {
pub x: f32,
pub y: f32,
pub z: f32,
}
#[spacetime_export]
impl From<Vec3> for glam::Vec3 {
fn from(v: Vec3) -> Self {
glam::Vec3::new(v.x, v.y, v.z)
}
}
#[spacetime_export]
impl From<glam::Vec3> for Vec3 {
fn from(v: glam::Vec3) -> Self {
Self { x: v.x, y: v.y, z: v.z }
}
}
Requested by @onx2 via the SpacetimeDB site.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the Rust code-generation and SpacetimeType procedural-macro entry points, then trace how shared types are emitted for clients. Define what #[spacetime_export] should accept and how generated clients should include exported impl blocks, using the Vec3/Vec2 conversion example as the completion case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100