Request Details

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.

  1. website-features added the feature-request label Jun 3, 2026
  2. Traced the type all the way down —
    crates/schema/src/def.rs TypeDef (line 1987) is constructed as just
    { accessor_name: ScopedTypeName, ty: AlgebraicTypeRef, custom_ordering: bool }
    — pure schema metadata, no code/tokens/impl body anywhere in it. The
    ModuleDef built from these is what every codegen backend
    (crates/codegen/src/{rust,typescript,csharp,cpp}.rs) operates on, so
    there's currently no path for an arbitrary impl block's function body
    to survive from your Rust source into any generated client language.

    A #[spacetime_export] that "just works" across all client languages
    would effectively require transpiling Rust expressions into 4+ target
    languages, which doesn't exist today. A realistic first version seems
    like it'd need to scope this to Rust-only client codegen (rust.rs),
    where the impl block's tokens could be re-emitted verbatim — no
    translation needed. C#/TS/C++/Unreal would need a different mechanism
    (or be explicitly out of scope for v1).

    Is that the direction you had in mind, or is there a different design
    already in mind for this?

Reopen this request?

The request will return to its prior live status.

Mark as Duplicate

Pick the request that Option to codegen impl blocks 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.